How to compare string field with reference field in transform map?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 11:29 PM
I have a field in Excel named "Schedule" it maps with "Schedule" in cmn_schedule_span table...
so here my issue is...
Suppose in Excel If I provide like "India Schedule" while transforming it is referring to "Schedule" which is a reference field due to this my transform map is not working...
so can anyone please explain how can we compare a string with reference field in transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 11:42 PM
Hi
I did the same with location data from XML and location column on sys_user table, the location field on user table is reference field from cmn_location table. But id doesn't get any error for mapping.
Please try manual mapping for fields, if you tried the auto-mapping option.
Mark helpful if it works for you.
Thanks,
Sanket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2021 11:48 PM
Hi, if the ‘name’ field is unique then you can map the reference record simply with a glide get in a before transform script. Something like
var myRecord = new GlideRecord(‘tableName’)
if(myRecord.get(‘nameField’, source.stringName)) {
target.referenceField = myRecord;
} else {
//log an error;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 12:15 AM
Hi,
Since your target field is reference you should be passing the unique sys_id
Use field map source script for this
Referenced value field name - sys_id
Script:
answer = (function transformEntry(source) {
// Add your code here
var incomingValue = source.u_schedule;
var gr = new GlideRecord("cmn_schedule");
gr.addQuery("name", incomingValue);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
else{
return -1; // don't allow update
}
})(source);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 03:33 AM
i.e., First time I ran the transform map, fields get updated...so now the schedule is with new data...
so if I run transform map again then no fields should updated because I am running the same data again...
in my case 12 are get updated only 1 get ignored...
please help ankur, I was not able to understand it trying from last 24 hours....attaching the screeshot