Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to modify current sys_id value with previous sys_id

Prasnajeet1
Giga Guru

Hi Expert

I have requirement where I have to update to the current sys_id value with the previous sys_id value.

For Example, In my dev isntance I have a CI as A and sys_id is ccbb23231212121. However, in my test instance same CI (A) has different sys_id value like kkkk121212121212. So, my requirement is to update the CI in the test instance with dev instance sys_id value.

 

Can someone please help me with the above requirement.  I have to write fix script for this or background script or anything. If possible, please help with script part as well. How can I achieve this requirement?

 

Thanks in Advanced

3 REPLIES 3

Manmohan K
Tera Sage

Hi @Prasnajeet1 ,

 

Changing the sys_id will not help you in this case.

You can delete the record in dev with sys_id  - ccbb23231212121 and import xml of record from test instance with sys_id - kkkk121212121212 into Dev instance

Hi Manmohan

 

Thats not the requirement actually. 

Markus Kraus
Kilo Sage

The following script will show how to reassign a SysID:

 

var ci1Gr = new GlideRecord('cmdb_ci'); // ... assume this is a valid record (e.g. via ci1Gr.get)
var ci2Gr = new GlideRecord('cmdb_ci'); // assume this is a valid record as well

var ci2SysID = ci2Gr.getUniqueValue(); // save the SysID before deletion
ci2Gr.deleteRecord();

// assign the SysID of CI2 to CI1
ci1Gr.setNewGuidValue(ci2SysID);
ci1Gr.update();