VAR Parameter in Events

vaprog
Member Posts: 1,163
Hi,
I started to implement Workflows in NAV 2017 and came about the following code fragments in Codeunit 1521 Workflow Response Handling:
The Event has the following prototype:
I found the following Documentation for the event.
So, because the event can have multiple subscribers, how is VAR ResponseExecuted handled by the event, does ExecuteResponse get back the answer of the subscriber that happened to be called last? Are the result of all the subscribers processed in some way (for example ORed together)? If so, where does this happen and / or where is the behavior defined / documented?
Does anybody have any insight?
I started to implement Workflows in NAV 2017 and came about the following code fragments in Codeunit 1521 Workflow Response Handling:
PROCEDURE ExecuteResponse@2(VAR Variant@1000 : Variant;ResponseWorkflowStepInstance@1001 : Record 1504;xVariant@1004 : Variant); ... ELSE BEGIN OnExecuteWorkflowResponse(ResponseExecuted,Variant,xVariant,ResponseWorkflowStepInstance); IF NOT ResponseExecuted THEN ERROR(NotSupportedResponseErr,WorkflowResponse."Function Name"); END;So here the Event OnExecuteWorkflowResponse is raised and then ResponseExecuted is checked and if not TRUE, an ERROR is raised.
The Event has the following prototype:
[Integration] LOCAL PROCEDURE OnExecuteWorkflowResponse@47(VAR ResponseExecuted@1000 : Boolean;Variant@1002 : Variant;xVariant@1003 : Variant;ResponseWorkflowStepInstance@1001 : Record 1504); BEGIN END;
I found the following Documentation for the event.
So, because the event can have multiple subscribers, how is VAR ResponseExecuted handled by the event, does ExecuteResponse get back the answer of the subscriber that happened to be called last? Are the result of all the subscribers processed in some way (for example ORed together)? If so, where does this happen and / or where is the behavior defined / documented?
Does anybody have any insight?
0
Best Answer
-
So, since the systen bugs me about not having marked some reply as answer I now compile this "Answer".
Although Slawek_Guzek's Answer was helpfull, it was not complete.
Also my comment might have been not all that clear and did not really answer all my initial questions.
So here we go:So, because the event can have multiple subscribers, how is VAR ResponseExecuted handled by the event,does ExecuteResponse get back the answer of the subscriber that happened to be called last?Are the result of all the subscribers processed in some way (for example ORed together)?If so, where does this happen and / or where is the behavior defined / documented?
0
Answers
-
The ResponseExecuted should be set by the code which 'knows' the function name and handles that certain function.
For example - this is my own handler subscribing to ExecuteResponse:
The event is raised with some specific value in Function Name, and if the subscriber handles that specific code it sets the ResponseExecuted. If the value in Function Name is unknown (no line in CASE statement matches it) the ResponseExecuted will not be updated - and if there is no other subscriber who 'knows' the function code then the standard code will throw unhandled response error.
When OnExecuteWorkflowResponse event is raised with specific function code it expects that some subscribers will handle it, and confirm this by updating ResponseExecuted.
It works OK even if you have more than one subscriber. You should handle specific function only once, but nothing stops you to have many supscribers to the OnExecuteWorkflowResponse, and some of them handling the same Function Name. All will work as long as you set the ResponseExecuted at some point (in one of the handlers).
The recommended flow is:raise OnExecuteWorkflowResponse with Function Name = "SomeFunctionA" Subscriber 1: "SomeFunctionA" known? No -> ignore/do nothing Subscriber 2: "SomeFunctionA" known? Yes -> do something / update ResponseExecuted Subscriber 3: "SomeFunctionA" known? No -> ignore/do nothing
if you take out Subscriber 2:raise OnExecuteWorkflowResponse with Function Name = "SomeFunctionA" Subscriber 1: "SomeFunctionA" known? No -> ignore/do nothing Subscriber 3: "SomeFunctionA" known? No -> ignore/do nothing
here the SomeFunctionA is not handled at all and the C1534 will throw an error after last subscriber has finished its code
If you have extra Subscriber 4 also knowing "SomeFunctionA" :raise OnExecuteWorkflowResponse with Function Name = "SomeFunctionA" Subscriber 1: "SomeFunctionA" known? No -> ignore/do nothing Subscriber 2: "SomeFunctionA" known? Yes -> do something / update ResponseExecuted Subscriber 3: "SomeFunctionA" known? No -> ignore/do nothing Subscriber 4: "SomeFunctionA" known? Yes -> do something / update ResponseExecuted
In the case above you may also decide that since ResponseExecuted passed from previous subscribers is TRUE, indicating that the "SomeFunctionA" has been already handled, you do nothing - like hereraise OnExecuteWorkflowResponse with Function Name = "SomeFunctionA" Subscriber 1: "SomeFunctionA" known? No -> ignore/do nothing Subscriber 2: "SomeFunctionA" known? Yes -> do something / update ResponseExecuted Subscriber 3: "SomeFunctionA" known? No -> ignore/do nothing Subscriber 4: "SomeFunctionA" known? Yes -> HasBeenHandled? Yes -> DoNothing / No -> do something / update ResponseExecuted
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031 -
Hi Slawek
Thank you for your answer.
At first, I did not consider a very obvious way of handling what I asked for in my question "Are the result of all the subscribers processed in some way". The obvious answer is:
The subscribers are called in sequence, and the next subscriber receives the result of the previous one.
In this way, the result is the logical OR of all subscribers IF (and only if) only the one that processed the event sets the flag to true. Any subscriber that does not handle the event must not set it to false.0 -
So, since the systen bugs me about not having marked some reply as answer I now compile this "Answer".
Although Slawek_Guzek's Answer was helpfull, it was not complete.
Also my comment might have been not all that clear and did not really answer all my initial questions.
So here we go:So, because the event can have multiple subscribers, how is VAR ResponseExecuted handled by the event,does ExecuteResponse get back the answer of the subscriber that happened to be called last?Are the result of all the subscribers processed in some way (for example ORed together)?If so, where does this happen and / or where is the behavior defined / documented?
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions