Update custom table record based on RITM variables when one of the tasks is marked as closedcomplete

Lakshmi Sharma
Tera Contributor

Hi,

I am trying to update a custom table record with RITM variables when task is closed as complete. I have a catalog item where I pick this record (ex:Incident) I will fill in variables and expectation is once my task in the flow is marked as complete by support team, I want variables to automatically update my incident fields with variable values submitted by requestor.

I am trying to achieve through run script but failing to update the (incident) record. Additionally I would need to verify the task state and only if state is closed complete this update must happen. My run script queries incident table with the variable  used to select target record. Once found the record I trying to map variables with incident fields but that dosent work as well.

 

Any sort of help is much appreciated, Thanks in Advance!!

1 ACCEPTED SOLUTION

@Lakshmi Sharma 

this should update and not insert

 

var TargRec = current.variables.target_record;
var UndRec = new GlideRecord('incident');
UndRec.addQuery('sys_id', TargRec);
UndRec.query();
if(UndRec.next()){
	UndRec.short_description = current.variables.shrt_desc;
	UndRec.description = current.variables.desc;
	UndRec.update();
}

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Lakshmi Sharma 

so what script did you start with? please share that

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar 

My script is like below: 

var TargRec = current.variables.target_record;
var UndRec = new GlideRecord ('table');
UndRec.addQuery('number',TargRec);
UndRec.query();
UndRec.short_description = current.variables.shrt_desc; (field 1)
UndRec.description= current.variables.desc; (field 2)
UndRec.update();

@Lakshmi Sharma 

use this

var TargRec = current.variables.target_record.getRefRecord();
TargRec.short_description = current.variables.shrt_desc; //(field 1)
TargRec.description= current.variables.desc; //(field 2)
TargRec.update();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar, Unfortunately the above script dint update the target record. Used exact same script as suggested.