How to set the parent of RITM to the CR created via workflow

Raphael Dizon
Mega Expert

Hello,

I have a workflow in which when you submit the form, it will create a RITM and a Change Request at the same time. Is it possible to set the CR created as the parent of the RITM created? If yes, how can I do it in the workflow. Thank you.

Kind Regards,

Raphael

1 ACCEPTED SOLUTION

I would suggest,

1. Add a RUN SCRIPT activity , in place of CREATE TASK.

2. Add below code for creating change request and setting parent of RITM:

var grc= new GlideRecord('change_request');

grc.initialize();

grc.cmdb_ci = current.cmdb_ci ; // current.cmdb_ci : this will copy CMDB from RITM to CHANGE

grc.field_Name_on_CR= current.field_Name_on_RITM; // replace with your values that you want to set 

var sysID =change.insert(); // store sys_id of change request created

current.parent  =  sysID  // This will set parent for RITM

current.update();

3. In this way you can avoid setting,issue mentioned on my above comment.

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

 

 

Thank you,
Abhishek Gardade

View solution in original post

14 REPLIES 14

Hi Raphael,

So in the parent field of sc_req_item you need to populate the CR?

you are creating change request using template

Regards

Ankur

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

Hi Raphael,

Ideally RITM has parent as Request as out of the box functionality

but parent field on sc_req_item table is always empty out of the box; it is only populated when someone created RITM from incident form using UI action

but still if you want then use this approach

create a run script activity in workflow

// query change request table and pick the latest record created and use that; the assumption is there is no other parallel process which created change request or else it will pick wrong change request

var sysId = '';

var gr = new GlideRecord('change_request');

gr.orderByDesc('sys_created_on');

gr.setLimit(1);

gr.query();

if(gr.next()){

sysId = gr.sys_id;

}

current.parent = sysId;

current.update();

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

how do I make RITM as a parent to change request(standard template).I have used this code to trigger standard change

var templateSysId = " sys_Id";
var changeRecord = new GlideRecord('change_request');
changeRecord.initialize();
GlideTemplate.get(templateSysId).apply(changeRecord);
changeRecord.insert();

Vishal Khandve
Kilo Sage

Hi Raphael,

As you are creating the change request from the WF. please dd the run script activity to add the created CR to the parent field on RITM.

 

Thanks,

Vishal

Monika2
Giga Guru

Hello Raphael,

Please share a screeshot for the run script activity which is responsible for creating both RITM and CR.

 

Regards,

Monika