BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  Is it possible to update Business Object data of a process instance using JavaScript API ?

    Posted Tue March 23, 2021 07:01 PM
    I mean, without using local variables tw.local.*
    The idea is that a process instance running a ServiceFlow can use JavaScript to search for another instance (tw.system.searchInstanceBiId()) to update a BO on that instance.

    Thanks.

    ------------------------------
    Eduardo Izquierdo Lázaro
    ------------------------------


  • 2.  RE: Is it possible to update Business Object data of a process instance using JavaScript API ?

    Posted Mon April 05, 2021 08:26 AM
    Let me ask a BPM expert I know to look into this...

    ------------------------------
    DAVID Jenness
    ------------------------------



  • 3.  RE: Is it possible to update Business Object data of a process instance using JavaScript API ?

    Posted Mon April 05, 2021 04:11 PM
    Below is JS code we used in IBM Case Manager to update BO on user actions on a case detail page. You can try and see if you can leverage similar concept. 

    require(["icm/base/Constants", "icm/model/properties/controller/ControllerManager"], 
    function(Constants, ControllerManager) {
       /* Get the coordination and editable objects from the event payload. */
       var solutionPrefix = payload.caseType.getSolution().getPrefix();
       var coordination = payload.coordination;
       var editable = payload.caseEditable;

       /* Use the LOADWIDGET coordination topic handler to obtain the controller binding */
       /* for the editable and to update the properties. */
       coordination.participate(Constants.CoordTopic.LOADWIDGET, function(context, complete, abort) {
          /* Obtain the controller binding for the editable. */
          var collectionController = ControllerManager.bind(editable);

          /* Start a batch of changes. */
          collectionController.beginChangeSet();

     /* Build the values for the Business Object Members */
     /* Assume all members to contain data for all rows     */
     /* In the view, we would see two rows like */
     /* 10, Baker Street, Costa Mesa, Oasis, California, USA*/
     /* 20, Ebay Street, Costa Mesa, Lotus, California, USA */
          var propValues = {};
          propValues.SAT_HouseNumber = ["10","20"];
          propValues.SAT_StreetName = ["Baker Street","Ebay Street"];
          propValues.SAT_CityName = ["Costa Mesa","Costa Mesa"];
          propValues.SAT_PropertyName = ["Oasis","Lotus"];
          propValues.SAT_StateName = ["California","California"];
          propValues.SAT_CountryName = ["USA","USA"];

     /* Get the property Controller of the Business Object. For instance, SAT_Residence */
          var residenceController = collectionController.getPropertyController(solutionPrefix + "_Residence");

     /* Get the members of the Business Object */
          var children = residenceController.getAttribute("boChildren").get();
     
     /* Set the individual value arrays to the child controllers */
     /* This would help in displaying the changes on Add Case    */
            for(var j=0;j < children.length; j++) {
           var childController = collectionController.getPropertyController(children[j]);
    var propname = solutionPrefix + "_" +  childController.getAttribute("name").get();
    childController.set("value",propValues[propname]);
            }
     
          var num_values = propValues.SAT_HouseNumber.length;

     /* Loop through the values and set it to the Business Object Controller. */
     var values = [];
          for(var i=0;i < num_values; i++) {
              var updateJson = {};
              updateJson.id = null;
              var props = [];
              updateJson.properties = props;
              for(var j=0;j < children.length; j++) {
    var prop = {};
    var childController = collectionController.getPropertyController(children[j]);
    prop.name = solutionPrefix + "_" +  childController.getAttribute("name").get();
    prop.dataType = childController.type;
    prop.cardinality = childController.cardinality;
    prop.value = propValues[prop.name][i] ;
    props.push(prop);
              }
              values.push(updateJson);
          }
     
          residenceController.set("value", values);

          /* Complete a batch of changes. This tells all subscribed widgets to refresh. */
          collectionController.endChangeSet();

          /* Call the coordination completion method. */
          complete();
       });
       
       /* Use the AFTERLOADWIDGET coordination topic handler to release the controller binding for the editable. */
       coordination.participate(Constants.CoordTopic.AFTERLOADWIDGET, function(context, complete, abort) {
          /* Release the controller binding for the editable. */
          ControllerManager.unbind(editable);

          /* Call the coordination completion method. */
          complete();
       });
    });



    ------------------------------
    Nitin Upasani
    ------------------------------



  • 4.  RE: Is it possible to update Business Object data of a process instance using JavaScript API ?

    Posted Mon April 05, 2021 06:33 PM
    Hi Eduardo,

    I don't think there's any other ways other than using tw.local and bindings in between input/output of parent process and child processes. I think that's how the product was designed to update business object data anyway. Would you elaborate more on your situation as for why tw.local and bindings are not sufficient? 

    Have a look into the JS API docs for process instance: https://www.ibm.com/docs/en/bpm/8.6.0?topic=apis-javascript-api-in-process-designer#TWProcessInstance
    There's no methods available to update any object during a process execution. 

    I've always used REST API to update process data during tasks execution or from user dashboards.

    Regards,
    Thong

    ------------------------------
    Thong Huynh
    Sydney NSW
    ------------------------------



  • 5.  RE: Is it possible to update Business Object data of a process instance using JavaScript API ?

    Posted Tue April 06, 2021 03:31 AM
    Thanks Thong, I came to the same JS API that you're suggesting, however after modifying the BO of the instance, It was not saved to the BD, it has no effect. But I will double check.



    Thanks.

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