Michael Jones -
Giga Sage

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!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post