10 Replies Latest reply on Jan 3, 2018 3:53 PM by xili

    How to serialize workflow instance executions?

    xili Apprentice

      Hello everyone -

      I have several workflow instances running at the same time from the same workflow for service request and I need to allow only one workflow instance to run. To pick up the winning instance, I used GetCounterValue/GetNextCounter functions in the workflow to have them figure out the winner who "sees" the original counter value + 1. Not sure where the issue is, but the execution results are not consistent - the number of instances executed is from 0 to 2 in different tests. I wonder maybe the GetNextCounter is not an "atom" operation, i.e., during the time when an instance read the counter, (system) increased it, and then returned the counter value, some other instance could do the same thing on the counter at any time point and therefore the final result is not predictable?? Anybody have a better method?? Thanks for any help. GL

        • 1. Re: How to serialize workflow instance executions?
          AlasdairRobertson ITSMMVPGroup

          Can you post a screen shot of your workflows?

           

          Assuming you are running the invoke workflow block yo can put these in series and use the wait for completion flag then once the first workflow finishes the next will start?

           

           

           

           

           

          • 2. Re: How to serialize workflow instance executions?
            xili Apprentice

            Thanks for the response; I appreciate it. I use "Wait" mechanism between the "logic parent and Children" workflows, but, in this case, a child workflow can have other parent workflows in the same service request; and in one service request, I need the child workflow be executed only once no matter how many parent workflows it may have. The child workflow creates a Task; I don't want the same task created multiple times.

            • 3. Re: How to serialize workflow instance executions?
              xili Apprentice

              Here is a basic execution thread of the workflows.

              • 4. Re: How to serialize workflow instance executions?
                AlasdairRobertson ITSMMVPGroup

                How about rather than using a counter you add a field/flag to the starting object so that once the workflow is invoked or just before it is invoked it sets a child1 flag to 1.  Then you can test that flag to see if the workflow has been run already.

                • 5. Re: How to serialize workflow instance executions?
                  xili Apprentice

                  That's a good idea, but the field/flag of the "starting object" will be a "shared" resource that will have the same issue I talked about.

                   

                  I believe GetNextCounter is a good base to build the exclusive access control mechanism. I've found that I didn't grab the base counters at the highest level of my workflow tree and after I changed it, my tests are okay so far.

                   

                  Thanks for your input anyway.

                  • 6. Re: How to serialize workflow instance executions?
                    xili Apprentice

                    I figured the issue may be how to pass the flag check result. The reason is that when I check the flag and get a result, I need to save the result, because the IF/Switch blocks can only compare field values.

                     

                    I tried different ways to save the value to a field without luck. The reason for the challenge is that the place to save the value has to be "local" to the workflow instance, otherwise it would be overwritten by other workflow instances in this multi-thread situation. So, a field in the service request or the request offering template won't work, because they are not "local" to a workflow instance.

                     

                    Can we save a value that is "local" to a workflow instance? Or are there other ways?

                    • 7. Re: How to serialize workflow instance executions?
                      AlasdairRobertson ITSMMVPGroup

                      A long shot but how about creating a new object to hold your values, put your counter value to a field on the ServiceReq object and then on your new Workflow values object.  Then you can store the workflow counter reference (not sure if you can get the workflow recid which would be better) and then you can store additional values against the workflow rather than the ServiceReq objects so you can then use workflow values across multiple objects.  You could even create a new relationship between all the objects and the workflow reference object for easy access to the shared values (search and link on counter value?).

                      • 8. Re: How to serialize workflow instance executions?
                        xili Apprentice

                        Interesting approach.. yes, the object created should be "usable" only by the workflow instance, but I seem to only be able to create the default service request object in a workflow. I guess that's the purpose of the "create object" block anyway. (By the way, workflows won't have recid, but should have something like process id, but I didn't find a way to see it.)

                         

                        Good news is that I spent the time to sort out the higher level callers to coordinate the calls so that the leaf workflows won't be invoked multiple times in one request. Lesson learned is maybe there is no way to control shared resource access.

                         

                        Thank you for your input, AlasdairRobertson!

                        • 9. Re: How to serialize workflow instance executions?
                          AlasdairRobertson ITSMMVPGroup

                          You are right the workflow is designed to run against the object that called it, you can trigger workflows from other objects using flags and quick actions so on your created object you could insert the workflow counterid (or other identifier) to allow a run for search and tie it all back and then use run for child actions to trigger sub workflows.  Rather messy in the long run but I think possible.

                          1 of 1 people found this helpful
                          • 10. Re: How to serialize workflow instance executions?
                            xili Apprentice

                            Yes, I can create other BO records from workflow instances, but there is still the same issue that how does a record be identified to be created by "me", if there is no workflow instance identification?