Using the global variable in the event subscriber method, declared in the event publisher codeunit, you have to perform following steps:
- Go the the property of the publisher event of type integration(only).
- In the property windows, change the property GlobalVarAccess to Yes.
- Go to the subscriber event method and create a parameter with the exact same name and type as that of the global variable declared in the event publisher code unit. You need to add manually in the parameter list each variable for each global variable you wish to access. If you set the parameter as Var in the event subscriber method then you change the value of global variable declared in publisher codeunit.
Again, you need to note that if the publisher object removes a global var you access, or changes it’s name, you will not get a compile error, but your subscriber will not get executed.
Scenario 1: Create a Global variable in custom codeunit which is publishing and raising an event, get the value of this global variable in the subscriber method. Got a fair idea? So try it first by yourself and then come back to see how I performed it.
- Create a new codeunit. Also create, publish and raise an event.
- Create a new global variable in this codeunit.
- Write the business logic.
- Create a new codeunit and a susbcriber method(you may create the subscriber method in the same codeunit).
- Define a parameter MyGlobal of type Text in the subscriber method.
- Write the business logic in the subscriber method.
- Run the codeunit(CU50001) raising the event.
- See the output in RTC.
Try By Yourself: Create a Global variable in custom codeunit which is publishing and raising two events, get the value of this global variable in the 1st event subscriber method and change the value of that global variable. Now get the new value in the second event subscriber method and display in MESSAGE(). Got a fair idea? So try it first by yourself don’t forget to share your success with me!
Leave A Comment