Share codeunit's custom global variables between events
Big disadvantage of events for code customisation is there stateless behaviour. This is especially hurting in codeunits. It would be very useful to find a way to share custom global variables in codeunit between events.
One way of doing this: Introduce codeunit extension object in AL. All event handlers defined in this object would share global variables.
Another approach would be: Introduce system global variable ‘ObjectSate’ in each codeunit and possibly other objects. ‘ObjectSate’ variable is visible in all event handlers subscribed to codeunit events. ‘ObjectSate’ variable is based on .NET Hashtable object allowing to save different type of objects in this variable. This option is easier to implement.
Thank you.
Why not use the database for storing and retrieving information? Use session guid as a key.. This also allows stacking of state info that can be pushed and popped which is more ‘thread’ safe I think?
From: rgrygoryshchak [email protected] Sent: Wednesday, May 22, 2019 7:19 AM To: microsoft/ALAppExtensions [email protected] Cc: Subscribed [email protected] Subject: [microsoft/ALAppExtensions] Share codeunit's custom global variables between events (#2557)
Big disadvantage of events for code customisation is there stateless behaviour. This is especially hurting in codeunits. It would be very useful to find a way to share custom global variables in codeunit between events.
One way of doing this: Introduce codeunit extension object in AL. All event handlers defined in this object would share global variables.
Another approach would be: Introduce system global variable ‘ObjectSate’ in each codeunit and possibly other objects. ‘ObjectSate’ variable is visible in all event handlers subscribed to codeunit events. ‘ObjectSate’ variable is based on .NET Hashtable object allowing to save different type of objects in this variable. This option is easier to implement.
Thank you.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/ALAppExtensions/issues/2557?email_source=notifications&email_token=AHFK7D26KYFHVIUS6VRQDTTPWVI4DA5CNFSM4HOUZ3E2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GVHGLBA, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AHFK7DYTBVVI5U4NEY5G6MLPWVI4DANCNFSM4HOUZ3EQ.
'“As part of the merger of Odyssey Foods LLC and Orca Bay Foods LLC, our name will be Orca Bay Foods LLC beginning on April 1, 2019 – and the domain for our email addresses will be changing to @orcabayfoods.com. Although your emails to me at an @ody.bz domain will get to me, please make a note of my new email address as listed above in this email. Thank you!”'. If the disclaimer can't be applied, take no action.
Using database for storing and retrieving information - this approach is similar to static variables in traditional programming (variables are visible from everywhere and share life cycle of session). Could probably achieve the same with variables defined in single-instance codeunits.
But I'm after variables that belongs to object (codeunit or table) and share life cycle of object they defined in.
In fact ‘ObjectSate’ variable with global get/set functions could be very useful in tables too. This would let us to pass table's state between events originated from different codeunits where table is passed as parameter.
Regards, Roman.
You can use several keys to specify which session, window, object, table, and variables you are storing for. Globally.
Stick this in a buffer table from your code and you can access it later in your code (from any session), and you can know exactly what you saved and exactly what to deserialize. You can also use it to tell your code what function it should call next (delegates): (pseudo): { UserSession: “abcde-f0134-etc etc”, BufferType: Table(Page,Report,MyCustomClass) State: { x: foo, m:bar, z:”Roman”, etc: { etc: ‘etcetera’ } }, Delegate: ‘doThisAfterImDone(var1, var2)’, Id: ‘123456-12345-12345-123456789’ }
(Using this sort of cookie approach could also allow you to continue in case the user’s system loses connection or pages get refreshed.)
The coding for metadata variables per type of item that only lasts as long as the object is defined in code sounds… complicated. As soon as a table/page/etc variable in code is released from the scope it would need extra code to strip itself of metadata? And every time an item is created in memory the system would have to attach a new metadata object to it? What about when your code queries tables, then loops thru the results – it would have to create the metadata object for each one?
Respectfully, Louis Kaplan
From: rgrygoryshchak [email protected] Sent: Thursday, May 23, 2019 1:23 AM To: microsoft/ALAppExtensions [email protected] Cc: Louis Kaplan [email protected]; Comment [email protected] Subject: Re: [microsoft/ALAppExtensions] Share codeunit's custom global variables between events (#2557)
Using database for storing and retrieving information - this approach is similar to static variables in traditional programming (variables are visible from everywhere and share life cycle of session). Could probably achieve the same with variables defined in single-instance codeunits.
But I'm after variables that belongs to object (codeunit or table) and share life cycle of object they defined in.
In fact ‘ObjectSate’ variable with global get/set functions could be very useful in tables too. This would let us to pass table's state between events originated from different codeunits where table is passed as parameter.
Regards, Roman.
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/microsoft/ALAppExtensions/issues/2557?email_source=notifications&email_token=AHFK7D74QQZVUU4H7AJ5TI3PWZH7HA5CNFSM4HOUZ3E2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWBON2Y#issuecomment-495118059, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AHFK7D5Q5VFFAU76O67XB7LPWZH7HANCNFSM4HOUZ3EQ.
'“As part of the merger of Odyssey Foods LLC and Orca Bay Foods LLC, our name will be Orca Bay Foods LLC beginning on April 1, 2019 – and the domain for our email addresses will be changing to @orcabayfoods.com. Although your emails to me at an @ody.bz domain will get to me, please make a note of my new email address as listed above in this email. Thank you!”'. If the disclaimer can't be applied, take no action.
There are new Protected Var concept implemented in master recently. It will help to address this issue.
Closing this, please create request for particular changes if still needed