How to create a duplicate RITM record along with the variable values ?

Sristi
Tera Contributor

Hi,

Trying to create a duplicate RITM record along with the variable values submitted by user.

Triggering this via script from scheduled job after checking certain conditions.

 

I am able to duplicate the ritm record using:

 

newReq.number = new NumberManager('sc_req_item').getNextObjNumberPadded();
newReq.insert();

 

The variables details related with ritm are not duplicated.

 

Any leads on how to duplicate the related variable values submitted by user with the original ritm ?

Please share any references to the tables with these variable data of ritm record or any dot walking required.

 

Thanks in advance,

Sristi 

 

 

2 REPLIES 2

SunilKumar_P
Giga Sage

Hi @Sristi, You can use the GlideappCalculationHelper to add the another RITM to the existing one. Can you try the below script?

 

var catItemId = "<catalogItem SysId>";
var requestId = "<requestSysId>";
var helper = new GlideappCalculationHelper();
helper.addItemToExistingRequest(requestId, catItemId, "1");

var parentRitm = new GlideRecord('sc_req_item');
parentRitm.addQuery('number', current.number);
parentRitm.query();
if(parentRitm.next()){
var grRITM = new GlideRecord('sc_req_item');
grRITM.addEncodedQuery('request='+requestId+'^number!='+current.number);
grRITM.query();
if(grRITM.next()){
grRITM.variables.requested_for = parentRitm.variables.requested_for.toString();
grRITM.update();
}
}

 

Regards,

Sunil

 

Pavankumar_1
Mega Patron

Hi @Sristi ,

I am not sure why you are trying to duplicate the RITM but can getvalues and set on the new record

current.variables.start_date //example get value and set it

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar