how to push updated variable value in workflow

niharika verma
Tera Expert

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.

 

1 ACCEPTED SOLUTION

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

8 REPLIES 8

I don't think debug mode would have any impact. Just keep in mind the workflow would not automatically progress, just when the new timer value is reached - maybe check the system time zone?

Try adding some logging and make sure you're getting values: 

gs.info('timer_name=' + timer_name)

gs.info('doc_id=' + doc_id);

gs.info('context=' + context);

gs.info('return_date=' + ritm.variables.return_date);

If any of those are blank or not the value you expect, there's an issue somewhere. Maybe the timer name is wrong?

Try taking your values and manually querying the tables and make sure you get records, etc. 

 

 

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

niharika verma
Tera Expert

Thank you Michael, it really did the magic šŸ™‚

Very helpful.

Glad I could help!

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

Hello @Michael Jones - 
This thread is helpful and thanks for keeping it open. I have a similar requirement which I'm unable to achieve. Could you please help on the same ?

Hello all,

Once I submit a request after entering all the details, an RITM is generated. So in this case the workflow captures the "Retirement date" variable and waits in the timer until it reaches the retirement date. Now, in the approval change I have made the "Retirement date" variable as editable so user can edit it and change the date and save it. So the workflow has to check for the new updated date and then again it should wait in the timer until the new retirement date has arrived. Let me know how can I achieve this please.

How can I push the updated variable and retrigger the timer again ?

Tia

HemamaniPrabha_0-1706537598367.png