BPM, Workflow, and Case

 View Only
  • 1.  How to start an optional unstructured task by code using JavaScript API?

    Posted Tue August 03, 2021 12:14 PM
    Edited by Stephanie Wilkerson Tue August 03, 2021 04:29 PM

    Hello,

    I have a process with an optional unstructured activity. I want to start this activity from another human Task of the same process by code (clicking a "Start Task" button).

    I'm trying to implement in a service flow using the JS API. It seems that  TWProcessInstance,taks only returns the tasks that are already active.
    So I'm trying to use TWProcessInstance,retrieveActivityList(ActivityListProperties properties, Integer maxRows , Integer beginIndex , Boolean checkAuthorization)

    However this API seems to be incomplete. Even when it is documented in JavaScript API available in processes and service flows it raises the following error.

    ReferenceError: "ActivityListProperties" not defined.

    I've tried to avoid the reference error passing
    a null value as parameter (to get all the activities without any filter) but it also raises an error because is expecting an object of type ActivityListProperties.

    How can I do? Am I using the right API?
    How can i get the tasks ready to start of a process instance and then start it?

    Thanks in advance



    ------------------------------
    Eduardo Izquierdo Lázaro
    Automation Architect
    DECIDE
    MADRID
    +34609893677
    ------------------------------


  • 2.  RE: How to start an optional unstructured task by code using JavaScript API?

    Posted Wed August 04, 2021 02:29 AM

    A technique I have used is leveraging the shared business object features like so:

    1. The ad-hoc activity is configured to start automatically based on a precondition expression e.g. a variable (which is part of a shared business object) becomes true
    2. The human task sets this variable when user clicks "Start Task". Remember to also set "Update content objects and shared business objects when saving the execution context"



    ------------------------------
    ZAFIRIS KERAMIDAS
    ------------------------------



  • 3.  RE: How to start an optional unstructured task by code using JavaScript API?

    Posted Wed August 04, 2021 03:34 AM
    Hi Zafiris, that's a good trick, thanks for sharing,

    In my case the optional unstructured task is repeteable which make things a bit more complex as you need to be switching on and off the variable in the shared BO.

    However, I still prefer a cleaner implementation using a SF. It should be possible as there is a documented JS API for that. 
    Does anybody knows how to use that API? why am I having unresolved references in the API?
    I cannot do: 
    var properties = new tw.object.ActivityListProperties();
    should I add any JS module as a File in order to use the API? 


    ------------------------------
    Eduardo Izquierdo Lázaro
    Automation Architect
    DECIDE
    MADRID
    +34609893677
    ------------------------------



  • 4.  RE: How to start an optional unstructured task by code using JavaScript API?

    IBM Champion
    Posted Wed August 04, 2021 04:36 AM
    Edited by Atanu Roy Wed August 04, 2021 04:36 AM
    Hi Eduardo,

    Now, I remember, you need to add Dashboards toolkit as dependency in your process app, those BO are in Dashboards toolkit.

    That should have documented in IBM KC.
    ------------------------------
    Atanu Roy
    ------------------------------



  • 5.  RE: How to start an optional unstructured task by code using JavaScript API?

    IBM Champion
    Posted Wed August 04, 2021 03:25 AM
    Hi Eduardo,

    I used this JS API till v8.5.7 but it seems the objects are not available from v8.6.
    So, I can think of two ways of starting an ad-hoc activity - 

    1. Using REST API, first get the ad-hoc activity id using (Process API -> Ad-Hoc Activities), then use Start Activity from Activity API.
    2. As ZAFIRIS mentioned, you can use a precondition as a variable and set the condition to start the activity when the variable is updated. 


    ------------------------------
    Atanu Roy
    ------------------------------



  • 6.  RE: How to start an optional unstructured task by code using JavaScript API?

    Posted Tue August 10, 2021 02:43 AM

    Hi Atanu, many thanks for your answer.

    You're right, adding the reference to the dashboard toolkit, I can query and locate my unstructured-optional-startable activity of the process. Now I have the id of the activity. However, as you said, I cannot find the right API to create a Task from the activity with status READY as to be CLAIMED by a user with the proper role in the Portal.

    The most plausible class to search for that API it is TWProcessInstance, because the activity should be started in the context of a concrete process instance, but I don't find.

    Does anybody else know if this API has been deprecated so I should find for alternative options?




    ------------------------------
    Eduardo Izquierdo Lázaro
    Automation Architect
    DECIDE
    MADRID
    +34609893677
    ------------------------------



  • 7.  RE: How to start an optional unstructured task by code using JavaScript API?

    IBM Champion
    Posted Tue August 10, 2021 03:07 AM
    Here is a piece of sample code - 
    var pi = tw.system.findProcessInstanceByID(tw.local.instanceId);
    
    var activitiyListProperties = new tw.object.ActivityListProperties();
    
    var activityListFilter = new tw.object.ActivityListFilter();
    activityListFilter.executionStateFilter = ["READY"];
    
    activitiyListProperties.filters = new
    tw.object.listOf.ActivityListFilter();
    activitiyListProperties.filters.insertIntoList(0, activityListFilter);
    
    var activities = pi.retrieveActivityList(activitiyListProperties).activities;
    
    for(var i=0; i < activities.listLength; i++){
        if(activities[i].name.indexOf(tw.local.activityName) > -1){
            tw.local.activityId = activities[i].id;
        }
    }
    
    var ai = tw.system.findActivityInstanceByID(tw.local.activityId);
    
    ai.start();​
    In the start method, you can optionally pass a user id to assign the task directly to that user in case the ad-hoc task is a human task.

    ------------------------------
    Atanu Roy
    ------------------------------