- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 10:31 PM
Hey!
I want to populate the conditions field in ServiceNow via script.
Scenario - We have requirement to populate the data in Special Handling notes table via excel sheet ,
For that I have created an import set , but I need to understand how we can populate the display value of reference field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 02:58 AM
So here is the answerrr,
Just map the fields and map the field which you want to add in conditions with excel.
After that write an OnAfter Transform Script -
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gt = new GlideRecord('sn_shn_notes');
gt.addQuery('sys_id', target.sys_id); //sys_id of created record
gt.query();
if (gt.next()) {
//gs.info('GOT THE MANAGER SYS_ID -- sys id of user'+target.sys_id);
var getUser = new GlideRecord('sys_user');
getUser.addQuery('name', source.u_primary_contact); //reference field value from excel
getUser.query();
if (getUser.next()) {
var sys_id = 'manager=' + getUser.sys_id;
gt.conditions = sys_id;
gt.update();
}
} else {
gs.info("GOT THE MANAGER SYS_ID -- record not found");
}
})(source, map, log, target);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 11:54 PM
Hi,
You need to ask them to share user_name or email details (unique) field data to identify user record. Using name of user may update incorrect values in the target table.
Once you get unique value for user you can use transform script (field mapping level) and get the user sys_id for given value and generate the encoded query(condition).
To update condition field you need to set value like
"manager=<sys_id of manager>"
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 01:17 AM - edited 01-25-2024 01:18 AM
Hi Anil ,
Thanks for the response .
I am trying to create a field map script for the field primary contract(Staging table field name)
How should i write the "return" value -
manager = sys_idOfUser i fetched above.
And also I want to abort the action if manager is not present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-25-2024 02:58 AM
So here is the answerrr,
Just map the fields and map the field which you want to add in conditions with excel.
After that write an OnAfter Transform Script -
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gt = new GlideRecord('sn_shn_notes');
gt.addQuery('sys_id', target.sys_id); //sys_id of created record
gt.query();
if (gt.next()) {
//gs.info('GOT THE MANAGER SYS_ID -- sys id of user'+target.sys_id);
var getUser = new GlideRecord('sys_user');
getUser.addQuery('name', source.u_primary_contact); //reference field value from excel
getUser.query();
if (getUser.next()) {
var sys_id = 'manager=' + getUser.sys_id;
gt.conditions = sys_id;
gt.update();
}
} else {
gs.info("GOT THE MANAGER SYS_ID -- record not found");
}
})(source, map, log, target);