How to update RITM in workflow scripts

peter_repan
Tera Guru

Hi all,

I would like to use Run Script activity in Workflow for updating RITM field based on some script logic.

I'm using current.update(), but when I validate or publish workflow, I got following warning:

ValidateScriptForCurrentDotUpdate

This workflow uses 'current.update()' in 1 JavaScript statements. When a record is inserted, current.update() can cause the workflow   to execute   an infinite loop. When a record is updated, current.update() causes all script engines to run twice. To avoid an infinite loop when a record is inserted, remove unnecessary current.update() calls from custom scripts.

The behavior of workflow is strange, because for each requested item I'm getting now two workflow instances (of the same workflow).

Is there any way/workaround how to update RITM in workflow scripts?

1 ACCEPTED SOLUTION

Hi Peter,



If you have created workflow on the RITM table then you can directly update the fields in a run script activity. Just add



current.ritm_field_name = current.variables.variable_name;



If the workflow is on a different table like request, then you need to first fetch RITM via Glide query.



Thank You


Please Hit Like, Helpful or Correct depending on the impact of response


View solution in original post

9 REPLIES 9

Jaspal Singh
Mega Patron
Mega Patron

Hi Peter,



You can remove current.update() & check it should work well.



Thanks,


Jaspal Singh




Hit Like or Correct based on impact of response.


Hi Jaspal,



of course it works fine if I remove current.update(), but I need somehow update my RITM in workflow.


Hi Peter,



What I understand is you need to update some fields on RITM form with the variables values.



If so, Kindly use something as below:


current.field_name=current.variables.variable_name;



Thanks,


Jaspal Singh




Hit Like or Correct based on impact of response.


Ivano B
ServiceNow Employee
ServiceNow Employee

Hi Peter



Jaspal is right. A script block in a workflow works as business rule on Before.


This means that the current record referenced can be updated directly without using any current.update();


Exactly in the same way as the business rule if you add current.update() on a before business rule the system will give you an error.



I hope this will help or answer your question and in case it does please mark it



Cheers


R0b0