I need to link RITM on Exisiting Change Request (in Related section)

AbdurRahmanSnow
Giga Guru

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();

}

1 ACCEPTED SOLUTION

@AbdurRahmanSnow 

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.

 

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

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@AbdurRahmanSnow 

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.

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

I think, the code should be as below, but it is not working properly.

workflow.info('Run Script Checking 3' + current.variables.change_request_number_1);
workflow.info('Line 2' + current.sc_req_item);

var cNumber = current.variables.change_request_number_1;

var cChange = new GlideRecord("change_request");
cChange.addQuery('sys_id', cNumber);
cChange.query();

if(cChange.next()) {
    cChange.sc_req_item = current.sc_req_item.sys_id;
    cChange.update();
}




@AbdurRahmanSnow 

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.

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

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.

111.jpg