Set 'Location' on sys_user record from 'current.street address' reference

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 03:40 PM
Hi all,
Wondering if you may be able to help out here? I am looking to create a Business Rule on the sys_user table to auto populate a users Location depending on their street address.
for example; if the address is Suite 4 16 Ave SW, It will populate the name of the location to the location field on the sys_user table.
I've tried the following script but doesn't seem to take affect:
(function executeRule(current, previous /*null when async*/) {
var nm = current.street.getDisplayValue();
current.location = nm;
})(current, previous);
Any help would be super appreciated. Thank you!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2022 06:01 AM
Hi
Using current.update in a After Business Rule is not at all a good practice and will suggest not to mention a bad practice approach.
I will suggest both you and
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2022 06:05 AM
Sure
I will update the above script.
Thanks for letting me know.
Regards,
Gunjan
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2022 06:09 AM
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var getStreet = current.street.toString();
var getLocation = fetchLocation(getStreet);
current.location = getLocation; // This will set the location field based on Street
function fetchLocation(Userstreet){
var gr = new GlideRecord('cmn_location');
gr.addQuery('street',Userstreet);
gr.query();
if(gr.next()){
return gr.sys_id.toString();
}
}
})(current, previous);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke