- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 03:09 AM
I have a requirement.
On a Catalog form, there is a Change Request reference field. So, when Catalog form gets submitted along with the Change Request number, an RITM gets submitted.
So, the requirement is, this RITM should be then linked on the Change Request Related Section (change number which we gave on the Catalog form).
How should I achieve this with Code on WorkFlow ? I have created a workflow on sc_req_item table. But I will use Run script action and will write code.
I have written some code but I am not sure of the working. Please help.
workflow.info('Run Script Checking 3' + current.variables.change_request_number_1);
var cNumber = current.variables.change_request_number_1;
var cChange = new GlideRecord("change_request");
cChange.addQuery('number', cNumber);
cChange.query();
if(cChange.next()) {
current.sc_req_item = cChange.sys_id;
current.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:45 AM
then you need to set parent field on RITM with the CHG
try this
Note: I don't know the variable type is string type
var cNumber = current.variables.change_request_number_1; // I assume this variable is reference type
var cChange = new GlideRecord("change_request");
cChange.addQuery('number', cNumber);
cChange.query();
if (cChange.next()) {
current.parent = cChange.sys_id;
current.update();
}
If the variable is reference type then simply use this
var cNumber = current.variables.change_request_number_1; // I assume this variable is reference type
current.parent = cNumber;
current.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
01-28-2025 03:17 AM
if it's a reference variable then do this
var cNumber = current.variables.change_request_number_1;
var cChange = new GlideRecord("change_request");
cChange.addQuery('sys_id', cNumber);
cChange.query();
if(cChange.next()) {
current.changeField = cChange.sys_id;
current.update();
}
If it's not a reference field then your script should work please give correct field name present on RITM table
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
01-28-2025 04:10 AM
I think, the code should be as below, but it is not working properly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 04:22 AM
so you want to set the RITM field which is a custom field on change_request
If yes then do this
var cNumber = current.variables.change_request_number_1; // I assume this variable is reference type
var cChange = new GlideRecord("change_request");
cChange.addQuery('sys_id', cNumber);
cChange.query();
if(cChange.next()) {
cChange.yourCorrectFieldNameHere = current.sys_id;
cChange.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
01-28-2025 04:35 AM
Ankur, on Change Request, under the Related Lists, what is the back-end of RITM (Requested Items)?
Please tell. I am unable to find it.