- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 07:46 AM
I have a transform that runs on the sys_user table. The transform populates the location field (name value) which, of course, is a reference to cmn_location. My problem is that some records in cmn_location are duplicate names, but one of the duplicates has longitude and latitude information so that's the record I always want bound to my user. Note that my imported data does not contain the long/lat so that is why I'm looking at manually entered long/lat data on the cmn_location table.
Example - Duplicate Locations:
I created an OnBefore transform script within the sys_user transform map, but my code isn't exactly right. Can someone help please? Ultimately, while the sys_user transform is running, the script needs to look at the location being populated for the user and only add the location from the cmn_location table that contains a longitude OR latitude.
var loc = new GlideRecord('cmn_location');
loc.addEncodedQuery('longitudeISNOTEMPTY');
loc.query();
if (loc.next()){
// loc.update();
target.location();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 10:37 AM
Hi Shane,
Instead of an onBefore Transform Script can you instead try the following in the field map for the location field in your Transform map:
In Field map check "Use Source Script"
Then in script field put the following:
answer = (function transformEntry(source) {
var ret = '';
var loc = new GlideRecord('cmn_location');
loc.addEncodedQuery('latitudeISNOTEMPTY^longitudeISNOTEMPTY');
//Assumes your source location field is the name of the location
loc.addQuery('name',source.u_location);
loc.query();
if (loc.next()){
ret = loc.getUniqueValue();
}
return ret; // return the value to be put into the target field
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 11:41 AM
dvp,
I tried but the script did not bind the user to the correct location. Since a solution was presented by David, I will proceed with that route. Your help is appreciated though.
Shane

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 11:50 AM
I think onBefore transform script value is getting over written with field map.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2019 11:54 AM
Yes, I think you are correct. It's good to know that is how the transform works.