I written following code in "wait for condition" in work flow to stop workflow until to close all task records for particular request item, But this not working .

srikanth241
Mega Expert

Hi Team,

I written following code in "wait for condition" in work flow to pause the workflow until to close all task records for particular request item, But this not working, even all the tasks are closed but still it is in wait for condition only. It is not moving to further activities.

All these tasks are created dynamically trough run script from inputs of list collector.

Any Idea or inputs can help me a lot

code:

var gRT = new GlideRecord('sc_task');

gRT.addQuery('request_item',current.sys_id);

gRT.addQuery('active',true);

gRT.query();

  if(gRT.hasNext()){

  answer = false;

  gs.log('if'+gRT.hasNext());

  }

  else{

  answer = true;

  gs.log('else'+gRT.hasNext());

  }

Thanks.

Developer CommunityDiscussExperts CornerCommunity CornerConnect

1 ACCEPTED SOLUTION

That's a good point. Workflows only re-check when the record used against the workflow (e.g. RITM, change request) is updated. Updating child records isn't going to trigger the workflow on the parent record. To do this, you could force an update on the request_item when an update to the sc_tasl table is made.



An AFTER BR on the sc_task table something like this



(function executeRule(current, previous /*null when async*/) {



var parent = new GlideRecord('sc_req_item');


parent.get(current.request);


parent.setForceUpdate(true);


parent.update();



})(current, previous);


View solution in original post

24 REPLIES 24

Hi Chuck,



When I am using this code it is showing unique code violation, Is there any other way to update parent record.



Thanks.


Can you include a screenshot of the unique code violation?


Chuck Thanks for your time for looking into this.


Following the violation i am getting when I try to use force update.


even I tried by updating a particular field, that is not working(not updating in the record).



find_real_file.png


Thanks


That's odd because that message seems to indicate that an insert is being done to try and create a new record with the same sys_id. Are you sure you have a parent.update() and not a parent.insert()? Please share the BR script with me that you have. (screenshots of the rest of the BR are also appreciated.)


Thanks for your great support Chuck, I achieved this task by writing the following code:


(function executeRule(current, previous /*null when async*/) {


        var wf= new Workflow();


        var gr=new GlideRecord('sc_req_item');


        if(gr.get(current.request_item)){


                            wf.runFlows(gr, update);


            }


    })(current, previous);




If I use below mentioned code I am getting duplication error.


  var parent = new GlideRecord('sc_req_item');


  parent.get(current.request);


  parent.setForceUpdate(true);


  parent.update();




Thanks