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

@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

@AbdurRahmanSnow 

Thank you for marking my response as helpful.

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

Super amazing. Thank you so much. You are very intelligent. God bless you