Sharing the global variable between events in AL extension

wolfskinwolfskin Member Posts: 84
Hi everyone,

I've created two EventSubscribers in a codeunit and I would like to use the global variable for these EventSubscribers.

The variable is define in first EventSubscriber but when code is working on second EventSubscriber. The variable is cleared.

There is any to shared the global variable for each EventSubscriber?


Example code for this scenario.
Codeunit 50000

var
  varGlobalVariable: Text;

EventSubscriber 1
  varGlobalVariable := 'a';

EventSubscriber 2
  Record.Value = varGlobalVariable;

varGlobalVariable in EventSubscriber 2 is blank when the code is working on it.

EventSubscriber 1 and EventSubscriber 2 are in the same standard function.


Thank you.

Best Answer

  • JJMcJJMc Member Posts: 60
    Answer ✓
    You need to make this codeunit as SingleInsance

Answers

  • JJMcJJMc Member Posts: 60
    Answer ✓
    You need to make this codeunit as SingleInsance
  • wolfskinwolfskin Member Posts: 84
    JJMc wrote: »
    You need to make this codeunit as SingleInsance

    Thank you JJMC, I've already tried your solution and it's work.

    But, I wonder what side effects will have to be careful about this property?.
  • JJMcJJMc Member Posts: 60
    I do not think it is a big deal.

    In fact, Microsoft refactoritation for the new versions, changed a lot of functions with this property if they have subscriptions so it is faster, because they start first time you invoque and they remain in memory until you quit the season that invoque them.
  • wolfskinwolfskin Member Posts: 84
    JJMc wrote: »
    I do not think it is a big deal.

    In fact, Microsoft refactoritation for the new versions, changed a lot of functions with this property if they have subscriptions so it is faster, because they start first time you invoque and they remain in memory until you quit the season that invoque them.

    Thank you for your answer :smile:
Sign In or Register to comment.