BPM, Workflow, and Case

 View Only
Expand all | Collapse all

How to refresh process-level variables from a human task?

  • 1.  How to refresh process-level variables from a human task?

    Posted Fri August 07, 2020 02:47 PM
    Hi guys,

    In a process there are long-running human tasks - from several days to several weeks. During this time the task is assigned to the starter user. After a while there are many tasks assigned to the user who don't know which task is which, I mean he/she can't identify the tasks using data entered on one of the coaches (say a customer name or customer ID) because the displayed process level variables are refreshed when the task is executed and closed.

    I know, that we can modify the narrative string of a taks, but we need to modify process-level variables displayed on the Portal.

    Is there any built-in function or finally a trick to refresh the process level variables from a task, without closing that task?

    Thx,

    ------------------------------
    ____________________
    Laszlo
    ------------------------------


  • 2.  RE: How to refresh process-level variables from a human task?

    Posted Fri August 07, 2020 03:19 PM
    You don't so much need to "trick" the engine as leverage one of the functionalities available in the tool.  I can think of a few ways to do this -

    Shared Business Objects

    I've not used these in the real world, but the purpose behind shared business objects was to keep multiple threads (tasks) working on the same data when they were doing parallel updates.  You would need to test that these changes also update the Process Context even if tokens aren't moving.  I'll note that when they first came out there were lots of difficulties with SBOs, which I think has wound up creating a bias against them.  

    If this provides the functionality you want it is likely the easiest approach with the least work.  Note however there were reports of performance impact in those early days, so be judicious with your use, or do the work to make sure the performance is adequate to your need.  

    Message Events

    You could have an event listener in parallel to the task whose entire purpose is to update the process variable values as the user executes the task.  You would then have the task invoke the message to provide the update.  This has the advantage of more fine grained control of when the update happens, but the down side of having to create an explicit set of code that a developer might miss in one or more cases, causing the values to not get updated.

    Independent Sync

    If you don't mind a bit of a delay in the values updating, I think you could leverage the ReST API or JS-API to periodically poll the instances and update the value using them.  This feels like a very ham-handed way to get what you need, and certainly would increase server load, but if this is for a minor set of the overall functionality, the approach might be worth it.

    Custom DB Approaches

    There are 2 of these, one with Sync, one with custom search.  Both of them would be based on realizing there is data here you may want to reference outside of the process execution context and saving that data to a custom DB instead of relying on Execution Context values.  Once you have that established you have 2 choices to keep tasks up to date.

    Sync -
    Like the ReST API above, when the DB gets a save you could also update the Process Context using an API call.  
    Custom Search -
    Replace the default portal with one that uses the custom DB as part of its search rather than relying on Process Variable values. 

    I'm sure there are other ways to do this, but those are the first that occur to me.



    ------------------------------
    Andrew Paier
    ------------------------------



  • 3.  RE: How to refresh process-level variables from a human task?

    Posted Sun August 09, 2020 11:37 AM
    Hi Andrew, 

    Thanks for your answer! The message event is a great idea!

    I tried to call the BPM REST services but unfortunately that wasn't successful. I started another thread on this. 

    Anyway, the message event will be the winner solution I think. Thanks again! 



    Az Outlook Mobile appból küldve





  • 4.  RE: How to refresh process-level variables from a human task?

    Posted Fri August 07, 2020 08:55 PM
    You should be able to use one of the many REST API calls. Preferably through a wrapper service. See one such API that allows bulk update here: https://www.ibm.com/support/knowledgecenter/SS8JB4/com.ibm.wbpm.ref.doc/rest/bpmrest/rest_bpm_wle_v1_process_instanceid_variables_put.htm
    Ibm remove preview
    View this on Ibm >


    ------------------------------
    Ajay Katre
    Salient Process
    ------------------------------



  • 5.  RE: How to refresh process-level variables from a human task?

    Posted Sat August 08, 2020 03:09 AM
    Hi Ajay,
    I see. Many thanks!

    ------------------------------
    ____________________
    Laszlo
    ------------------------------



  • 6.  RE: How to refresh process-level variables from a human task?

    Posted Mon August 10, 2020 01:47 AM
    Hi Laszlo,

    Another way to do this it to use the tw.system.updateCurrentInstanceVariablesByCurrentTaskOwner() API available in a Service Flow.  

    ------------------------------
    Sebastian Carbajales
    ------------------------------



  • 7.  RE: How to refresh process-level variables from a human task?

    Posted Mon August 10, 2020 02:29 AM
    Hi Sebastian, 

    Never seen that function... I will try it. 

    Thanks! 


    ------------------------------
    ____________________
    Laszlo
    ------------------------------



  • 8.  RE: How to refresh process-level variables from a human task?

    Posted Mon August 10, 2020 11:05 AM
    Hi, 

    I found this for the function from which Sebastian wrote:

    updateCurrentInstanceVariablesByCurrentTaskOwner(Object values , Boolean isTopLevel) Updates the current instance variables by current task owner.

    But nothing more. Do anybody have any further info about using it? Or at least an example? How to pass the name(s) and value(s) of variable(s) to modify? What means isTopLevel? What if it is false or true? 

    Thx,

    ------------------------------
    ____________________
    Laszlo
    ------------------------------



  • 9.  RE: How to refresh process-level variables from a human task?

    Posted Mon August 10, 2020 11:34 AM
    Here is an example of how to update a variable represented by a complex BO. 

    var tw_object = new TWObject();

    // 'theVariable' is the name of the variable in the parent process.  'myLocalVariable' is a variable holding the value that needs to be updated.
    tw_object.setPropertyValue("theVariable", tw.local.myLocalVariable); 

    // 'isTopLevel' is true when this task is running on the root process model, false if it is running in a linked process or subprocess.
    tw.system.updateCurrentInstanceVariablesByCurrentTaskOwner(tw_object, tw.local.isTopLevel);


    For a simple type you could pass  a JSON object like this:

    var values = "{'theVariable':'A string value'}";
    tw.system.updateCurrentInstanceVariablesByCurrentTaskOwner(values, tw.local.isTopLevel);


    ------------------------------
    Sebastian Carbajales
    ------------------------------



  • 10.  RE: How to refresh process-level variables from a human task?

    Posted Mon August 10, 2020 12:56 PM
    Hi Sebastian, 

    Many thanks for the example! 


    ------------------------------
    ____________________
    Laszlo
    ------------------------------



  • 11.  RE: How to refresh process-level variables from a human task?

    Posted Fri September 02, 2022 09:20 AM
    Hi Sebastian,

    I used your suggestion on my process and it works well , but my complex object contains a date parameter. And when I add that date parameter to json, object is not refreshed. 

    I put the date object value directly from my variable , also I tried adding it with this format: Year-Month-DateTHour:Minute:Second.MillisecondZ as like a string value.

    Do you have any idea why it is not refreshing when I use date parameter?

    Thank you.

    ------------------------------
    Bahar Gülşe
    ------------------------------



  • 12.  RE: How to refresh process-level variables from a human task?

    Posted Thu October 26, 2023 02:41 PM

    Hello Bahar , 

    May be its too late in this conversation - but for future reference it might be helpful to others

    Lets consider a variable futureDate is of date type

    var futureDate = tw.local.futureDate?tw.local.futureDate.toNativeDate().toISOString():null ;

    Now pass this variable to variable as date parameter, it will accept it.

    Thanks



    ------------------------------
    Gona Deepak
    ------------------------------



  • 13.  RE: How to refresh process-level variables from a human task?

    Posted Wed February 21, 2024 09:53 AM

    Hi Bahar,

    How did you manage to update a complex variable?

    In my case I have a variable "Request" of type "Request".

    It looks like this: request.InfoRequest.Status

    I am trying to update this process variable variable from a Interface task by calling a service.

    I tried like this: (tw.local.status is passed to this service from the InterfaceTask

    var tw_object = new TWObject();
    tw_object.setPropertyValue("request.InfoRequest.Status", tw.local.status); 
    tw.system.updateCurrentInstanceVariablesByCurrentTaskOwner(tw_object, true);

    The above implementation seems to not work.



    ------------------------------
    Madalin Florea
    ------------------------------