- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 01:57 AM
Hello,
I am writing script which is part of integration where I am inserting new records to the table in loop.
Problem is that I need to insert record with specific sys_id, so during next integration cycle, records will be in sync, and already inserted will be only updated.
When I tried to do something like:
gr.sys_id = "foreign_sys_id"
gr.insert();
it is ignored after insert and another sys_id is automatically generated.
I know that it is possible to insert own sys_ids by XML import, but I don't know if there is any methods which could be used in scripts.
Or is there any other way how to override autogenerating of sys_ids on insert and force my own?
Thank you
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 04:28 AM
OK, so I think I found an answer by myself.
When you are using GlideRecord object for insert into database, there is method setNewGuidValue which let you set own sys_id.
http://wiki.servicenow.com/index.php?title=GlideRecord#setNewGuidValue
for example:
var gr = new GlideRecord("u_integrated_table");
gr.initialize();
gr.u_col1 = "something";
gr.u_col2 = "else";
gr.setNewGuidValue("ac3b4eb1db3032004f575740cf9619ba");
gr.insert();
Will really set sys_id of newly created object as ac3b4eb1db3032004f575740cf9619ba
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 03:07 AM
Hi Jan,
I don't believe this is possible and for many reasons with system and data integrity being fundamental, however considering your question and the context, I believe it would be better to take a step back ask a few questions and also follow some best practice and common integration steps.
Question: Is the integration between 2 ServiceNow instances?
If so, as you point out, it is possible to import records from one SN instance to another and maintain the system ID. If this was performed as a 1 time load wouldn't this actually solve the issue? The 'next integration cycle' as you refer to would already recognize and match any existing records and update instead of insert existing records?
(Without trying to get too technical and go into lengthy discussion)
If the integration is between ServiceNow and a non ServiceNow system, its common practice to store the External ID of any imported records within ServiceNow (ie create a new field storing the External systems unique ID).
System ID's should be immutable (cant be changed) and unique. This newly created field would be used as the correlation ID and unique identifier to be used as part of your integration / next integration cycle.
Please mark as correct and/or helpful via the the post link (insert record with given sys_id ) to help close out open question in the community.
Thanks,
Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 03:31 AM
Hello Robbie,
thanks for answer. Situation is that we have several SN instances and this integration is part of synchronization of foundation data from production instance to others.
So far we handle this that script wrote data into stage table and than it was processed by transform map (sys_id synchronization worked).
Goal was to leave stage tables and transform maps and, because instances are same, let 1:1 import be automatic.
Only problem is with sys_ids, if I could somehow used methods used in native XML import, or something like that.
Is it possible to call XML import in script? it can hadle sys_id import
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2017 04:28 AM
OK, so I think I found an answer by myself.
When you are using GlideRecord object for insert into database, there is method setNewGuidValue which let you set own sys_id.
http://wiki.servicenow.com/index.php?title=GlideRecord#setNewGuidValue
for example:
var gr = new GlideRecord("u_integrated_table");
gr.initialize();
gr.u_col1 = "something";
gr.u_col2 = "else";
gr.setNewGuidValue("ac3b4eb1db3032004f575740cf9619ba");
gr.insert();
Will really set sys_id of newly created object as ac3b4eb1db3032004f575740cf9619ba