- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2025 11:29 PM
I need to have source script for reference field for company and location fields in user table to load data.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:46 AM
something like this for company, ensure "Referenced value field name" -> sys_id
answer = (function transformEntry(source) {
// Add your code here
var incomingValue = source.u_companyname;
var gr = new GlideRecord("core_company");
gr.addQuery("name", incomingValue);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
else{
return -1; // don't allow update
}
})(source);
something like this for location, ensure "Referenced value field name" -> sys_id
answer = (function transformEntry(source) {
// Add your code here
var incomingValue = source.u_locationname;
var gr = new GlideRecord("cmn_location");
gr.addQuery("name", incomingValue);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
else{
return -1; // don't allow update
}
})(source);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:40 AM
function getID(ID,table){
// returns the sys_id, Company: core_company, location: cmn_location
var companyid= new GlideRecord(table);
companyid.addQuery("sys_id",ID);
companyid.query();
if(companyid.next())
{
return companyid.sys_id;
}
return ;
}
// source.your import set field for getting the importset value
Mark correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:46 AM
something like this for company, ensure "Referenced value field name" -> sys_id
answer = (function transformEntry(source) {
// Add your code here
var incomingValue = source.u_companyname;
var gr = new GlideRecord("core_company");
gr.addQuery("name", incomingValue);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
else{
return -1; // don't allow update
}
})(source);
something like this for location, ensure "Referenced value field name" -> sys_id
answer = (function transformEntry(source) {
// Add your code here
var incomingValue = source.u_locationname;
var gr = new GlideRecord("cmn_location");
gr.addQuery("name", incomingValue);
gr.query();
if (gr.next()) {
return gr.getUniqueValue();
}
else{
return -1; // don't allow update
}
})(source);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader