Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

multiple records update on setWorkflow(false)

Mohammed Lais1
Mega Guru

Hi

i am trying to update multiple ritm records through workflow.

i am using the below code.

var req = current.request;

  var gr = new GlideRecord('sc_req_item');

  gr.addQuery('request',req);

  gr.orderBy('number');

  gr.query();

  while(gr.next()){

  gr.variable_pool.test_access_created="true";

  gr.update();

  }

this is updating only one record.but the query is fetching multiple records.

if i add

gr.setWorkflow(false);

before gr.update();

all the records are getting updated perfectly.

can we update the multiple records without making the workflow as false?

12 REPLIES 12

Yes Chuck,


in 1st item workflow i am using run script activity   to update one catalog variable(which will be present in ritm form under variable editor for 2nd to 5th items).


and in 2nd workflow(using for 2nd to 5th items) i am using wait for condition activity and checking whether the catalog variable is updated or not.


Hi Mohammed,



Thank you for the explanation. Your solution sounds good. You will have to do some debugging on those scripts to ensure you are finding the right records, retrieving the proper/expected values, and moving on in the workflow. Without eyes on screen, and hands on keyboard, it is difficult for me to debug a workflow via the community.



If you continue to run in to issues, I recommend seeking the help of customer support.   Good luck!



HI Service Portal - ServiceNow


Contact Support | ServiceNow



FYI - A waitfor condition and waitfor event are similar in function, but not the same.


Hi Chuck,


Thank You for spending your valuable time for helping me.



Actually i came with another solution for this issue.  


In 1st worflow to update catalog variable in remaining 4 ritm forms, i am using updatemultiple() instead of update()..


If i use updatemultiple() i can able to update multiple records at a time(may be   before 2nd workflow wait for condition is triggered).



one problem in this approach is we cannot directly assign values to the catalog variable field, instead we have to use setValue() function to update.


But for populating variables, setValue() function is not working.(using setValue() i can able to populate ritm attributes but not catalog variables in ritm form.