How to create a duplicate RITM record along with the variable values ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 02:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 03:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-28-2023 03:28 AM
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
ServiceNow Community MVP 2024.
Thanks,
Pavankumar