to create exact copy of a catalog item with my own sysid

Sachin Gavhane
Giga Guru

Hi, I have a requirement where I need to make a copy of the catalog items and its complete related data [ all variables / catalog client scripts] , but the copied catalog item should have sysid given by me.

 

with below script , I am able to create blank catalog item with the given sysid, but i want to make it a copy of another catalog item.

//var now_GR = new GlideRecord('cat_item');
//now_GR.setValue(
'short_description', 'The third floor printer is broken'); //now_GR.setNewGuidValue('eb4636ca6f6d31005be8883e6b3ee333');
//now_GR.insert();
//gs.info(now_GR.getValue(
'sys_id'));

can someone pls help me with this query?

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Sachin Gavhane 

so basically you want to copy catalog item with all stuff i.e. variables, variable set, catalog client script or catalog UI policy

what's your business requirement to copy?

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

Business requirement is:

 

we have written ATF testcases on catalog items which are sysid specific.
After integration, we may import catalog items with the same name but sysid will change and old catalog items may get deleted. In this scenario ATF test cases may fail.
So, we want to clone newly arrived catalog items with the old sysids.

Requesting you to help me with this issue.
Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

@Sachin Gavhane 

Did you try to use the OOB Copy UI action on your catalog item?

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

Hi @Ankur Bawiskar 
Happy to see your reply.
I wish to create newly created catalog item with the given sysid.

For example: In the below script , it creates a catalog item with the given sysid-- "eb4636ca6f6d31005be8883e6b3ee333"
//var now_GR = new GlideRecord('cat_item');
//now_GR.setValue(
'short_description''The third floor printer is broken'); //now_GR.setNewGuidValue('eb4636ca6f6d31005be8883e6b3ee333');
//now_GR.insert();
//gs.info(now_GR.getValue(
'sys_id'));

Requesting you to help me with this regards.
thanks and appreciate you for your help