- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 07:20 PM
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!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 10:43 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 10:17 PM
script I shared will work with below assumptions
1) target_record is a reference variable which refers to incident table
2) the variable names are correct for short description and description
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 10:34 PM
Hi @Ankur Bawiskar I am testing this on Incident table for now, field names are correct I did verify. Script suggested throws error as cannot set property "short_description" of undefined to (passed value). Below script I tried by mistake and that is creating a new record.
// var TargRec = current.variables.target_record.getRefRecord();
// var UndRec = new GlideRecord('incident');
// UndRec.addQuery('sys_id', TargRec);
// UndRec.query();
// UndRec.short_description = current.variables.shrt_desc;
// UndRec.description = current.variables.desc;
// UndRec.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 10:43 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 11:19 PM
Hi @Ankur Bawiskar , Thank you for super quick responses that worked!!! Please also suggest on this part, I have 2 parallel tasks, if any of these tasks are closed complete, only then my script should update the incident with variables else ignore. Above that update log should be updated by system.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2023 11:39 PM
Glad to know.
Please mark my response as correct as I answered your original question.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader