Script to copy all contents of a RITM to a new RITM

Shant Cancik
Tera Contributor

Is there an easy way to copy a RITM and all its variable values onto a new RITM with a new number? I'd like to create a new RITM and just change one variable. I'm currently creating a script to copy fields and variables one by one. Is there an easier solution?

7 REPLIES 7

Mike Allen
Mega Sage

my favorite way is to query the dictionary for all the fields, then loop through and write the data over:



var dict = new GlideRecord(sys_dictionary');


dict.addQuery(;nameSTARTSWITHsc_req_item^element!=NULL');


dict.query();


var element_array = [];


while(dict.next()){


        element_array.push(dict.element);


}



var new_req_item = new GlideRecord('sc_req_item');


new_req_item.initialize();


for (i=0;i<element_array.length;i++){


        new_req_item.element_array[i] = current.element_array[i];


}


new_req_item.insert();



Or something like that.   I have not tested it lately, but it has worked for me in the past.



Mike


Dave Smith1
ServiceNow Employee
ServiceNow Employee

If you have access rights, you could open the RITM then do "Insert" once you've done a change.



Is this for a one-off or a regular basis?


I have a catalog item that launches the RITM. The catalog item is for request access or removal to an application (through a select box variable with a choice whether to add or remove. During fulfillment for add requests, a date gets set on the RITM record to serve as the end date for account access.



Now I'm trying to create a scheduled job that scans that variable date on RITMS daily and when the date matches the current date I want to resubmit the same catalog item with pretty much all the same information EXCEPT this time the select box choice "remove" is picked. Selecting that would cause the appropriate chain of events in my workflow to remove the user.



The more that I think about it, I'm not sure if I want to actually create a duplicate RITM directly or somehow just resubmit the catalog item. Because when a catalog item is submitted it also creates a Request record which I'd like to still happen.


The more that I think about it, I'm not sure if I want to actually create a duplicate RITM directly or somehow just resubmit the catalog item. Because when a catalog item is submitted it also creates a Request record which I'd like to still happen.


That was my thinking.



It sounds more like you want two things to happen upon the submission of one RITM, rather than duplicate RITMs.



Perhaps you simply want to amend the RITM workflow, appending additional tasks as necessary.



Generally speaking:


  • "I want a script to" should always be met with "why does it need to be a script? Are there any other ways? Can we avoid scripting?"
  • "help me along this journey" is usually met with "first, tell me your desired destination. Then we can discuss if your route is a good one."