- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-30-2020 07:29 AM
using a workflow an RITM was created. Now, I want to update a variable value in this RITM form.
the workflow has a timer which is dependent on a variable value. I was able to update the variable value in RITM form, how do I push that value in the workflow, so it progresses on the new value and forgo what was originally entered. I just want the workflow to have the updated value of the variable and progress with it. Currently, it is staying at the timer activity.
Timer based on script:
var terDate = current.variable_pool.return_date.getDisplayValue();
workflow.debug('The Input time is ' + terDate);
var waitSecs = gs.dateDiff(gs.endOfNextWeek(), terDate, true);
workflow.debug('Waiting time is: ' + waitSecs);
answer = waitSecs;
Using background script, I update the return_date variable value
var ritm = new GlideRecord('sc_req_item');
ritm.get('3e3afce8db68d01084c696cadb961979');
ritm.variables.return_date = '2020-06-29 13:00'; ---> new value which was updated on the RITM form after it was submitted
ritm.setWorkflow(false);
ritm.autoSysFields(false);
ritm.update();
How can I trigger the workflow to proceed.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-30-2020 05:58 PM
Well...
When a workflow timer activity is triggered, the result is that a scheduled job is created in the sys_trigger table. The challenge is finding the right entry to update - but it can be done.
Something like this should give you what you are looking for. You would need to replace the timer_name with the name of your timer activity in your workflow and run something like this:
//First we need to get your RITM and set the new variable value.
var ritm = new GlideRecord('sc_req_item');
ritm.get('3e3afce8db68d01084c696cadb961979');
ritm.variables.return_date = '2020-06-29 13:00'; //---> new value which was updated on the RITM form after it was submitted
ritm.setWorkflow(false);
ritm.autoSysFields(false);
ritm.update();
//Next, we have to get the context for the workflow running against your ritm.
var context = '';
var wf = new GlideRecord('wf_context');
wf.addQuery('id', ritm.sys_id);
wf.query();
while(wf.next()) {
context = wf.getValue('sys_id');
}
//this is the name of your timer activity in the worklow - since you can have more than one.
var timer_name = 'This is my timer!'; //<---Change to the name of your timer
var doc_id = '';
//Now we have to get the executing workflow activity records associated to the context.
var wf_executing = new GlideRecord('wf_executing');
wf_executing.addQuery('context', context);
wf_executing.query();
//Now we cycle through the activities to find the one we have named.
while(wf_executing.next()){
if(wf_executing.activity.name == timer_name) {
doc_id = wf_executing.getValue('sys_id');
}
}
//Now, we use everything we have learned to find the right entry in the scheduled job table.
var schedule = new GlideRecord('sys_trigger');
schedule.addQuery('document_key', doc_id );
schedule.query();
while(schedule.next()) {
//and here comes the magic
//update the next_action field using the value in the appointment_time variable.
schedule.next_action = ritm.variables.return_date; //<---Change to your variable name
schedule.update();
}
//Success!
Hope this helps!
If this was helpful or correct, please be kind and click appropriately!
Michael Jones - Proud member of the CloudPires Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-30-2020 05:58 PM
Well...
When a workflow timer activity is triggered, the result is that a scheduled job is created in the sys_trigger table. The challenge is finding the right entry to update - but it can be done.
Something like this should give you what you are looking for. You would need to replace the timer_name with the name of your timer activity in your workflow and run something like this:
//First we need to get your RITM and set the new variable value.
var ritm = new GlideRecord('sc_req_item');
ritm.get('3e3afce8db68d01084c696cadb961979');
ritm.variables.return_date = '2020-06-29 13:00'; //---> new value which was updated on the RITM form after it was submitted
ritm.setWorkflow(false);
ritm.autoSysFields(false);
ritm.update();
//Next, we have to get the context for the workflow running against your ritm.
var context = '';
var wf = new GlideRecord('wf_context');
wf.addQuery('id', ritm.sys_id);
wf.query();
while(wf.next()) {
context = wf.getValue('sys_id');
}
//this is the name of your timer activity in the worklow - since you can have more than one.
var timer_name = 'This is my timer!'; //<---Change to the name of your timer
var doc_id = '';
//Now we have to get the executing workflow activity records associated to the context.
var wf_executing = new GlideRecord('wf_executing');
wf_executing.addQuery('context', context);
wf_executing.query();
//Now we cycle through the activities to find the one we have named.
while(wf_executing.next()){
if(wf_executing.activity.name == timer_name) {
doc_id = wf_executing.getValue('sys_id');
}
}
//Now, we use everything we have learned to find the right entry in the scheduled job table.
var schedule = new GlideRecord('sys_trigger');
schedule.addQuery('document_key', doc_id );
schedule.query();
while(schedule.next()) {
//and here comes the magic
//update the next_action field using the value in the appointment_time variable.
schedule.next_action = ritm.variables.return_date; //<---Change to your variable name
schedule.update();
}
//Success!
Hope this helps!
If this was helpful or correct, please be kind and click appropriately!
Michael Jones - Proud member of the CloudPires Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2020 07:03 AM
Hi Michael,
The script has been very useful and helped in pushing the updated variable value in a running workflow.
However, this time when the script was used, it updated other scheduled jobs as well. Next action of jobs were updated to return date variable updated in the script.
The script is used to update only one RITM, but somehow it ended up updating 200+ schedule jobs > next action.
Is it because of :
var doc_id = '';
Please can you advise.
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2020 07:15 AM
Not exactly, and I apologize; there should be a check to make sure you are returning a valid doc_id before committing to the update. Should add an If statement in the final block to make sure that there is a doc_id and not the default value of ''.
//Now, we use everything we have learned to find the right entry in the scheduled job table.
//But only if an actual doc_id was returned!
if(doc_id != '') {
var schedule = new GlideRecord('sys_trigger');
schedule.addQuery('document_key', doc_id );
schedule.query();
while(schedule.next()) {
//and here comes the magic
//update the next_action field using the value in the appointment_time variable.
schedule.next_action = ritm.variables.return_date; //<---Change to your variable name
schedule.update();
}
}
Hope this helps!
If this was helpful or correct, please be kind and click appropriately!
Michael Jones - Proud member of the CloudPires Team!
Michael D. Jones
Proud member of the GlideFast Consulting Team!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2020 07:55 AM
I just ran this on a temp instance which is in debug mode. It did update the RITM value but not pushed the updated value in workflow. Workflow didn't progress.
I am not sure if this is because of the instance is in debug mode. can you please advise.
Regards
Niharika Verma