Data import from excel to ServiceNow when duplicate values are present in SNOW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2023 11:45 PM
Hello all,
We would like to import the data from excel to ServiceNow table using Load data/transform maps, but the concern here is we have duplicate values in ServiceNow table.
For example: we have 3 fields in SNOW table, A, B, C. We need to import "C" field data into snow where as A & B fields data is already existing.
Record:1
A value has India.
B value has Bangalore
Record:2
A value has India
B value has Hyderabad
Record:3
A value has Germany
B value has Hyderabad
Record:4
A value has Germany
B value has Bangalore
Here I need to consider A & B values, since some cases both are not unique alone to impot C.
How can I do that in transform scripts?
Please assist.
Thanks!
Ksnow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2023 12:45 AM
You need to use what ServiceNow calls Conditional coalesce.
It is basically a Field map where the target field is Sys ID and it is marked as a scripted one.
In the script of such a Field map one needs to write code that looks up what record needs to be updated and
- sets global variable answer to the sys_id of the record found (obviously if found) - in this case that record will be updated -or
- sets global variable answer to -1 if no record is found - in this case a new record will be created.
In your case you would need to write a script that searches the table where fields A and B have the same values as the transformed record and sets global variable answer to that record's sys_id - if found, otherwise sets global variable answer to -1.
E.g. to use your example, if the transform record contains A == India and B == Bangalore, it should set global variable answer to the sys_id of Record:1, if the transform record contains A == France and B == Bangalore, it should set global variable answer to -1, cause no such record exists/will be found.
Do have a look at the docs page referenced above for perhaps clearer examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2023 10:48 PM
Hello,
Could you please share the script based on my requirement? and also please let me know where to put the script.
Thanks,
Ksnow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 12:46 AM
I could try, but I will need the names of the source fields, and the target fields - especially the type of the latter. Can you share those?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2023 12:59 AM
Also I should mention that if field A in the source data matches the text or display value in field A in the target table and the same for field B, all you need to do is to map those fields and mark them as Coalesce: