- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 06:20 PM - edited 07-22-2025 06:21 PM
Hi,
Can someone please advise how I can configure REQ form to populate location based on the "Requested for" user?
I have been able to create business rule to populate the location for the new requests but for the existing ones I can't figure out what I need to select in Form Builder under location to make it work.
I have tried dot walking in location, dependent field to the "Requested for" location but that didn't work.
Thank you for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 08:16 PM
you can use a fix script to update it for older REQs
Something like this
updateLocation();
function updateLocation() {
try {
var req = new GlideRecord('sc_request');
req.addEncodedQuery('locationISEMPTY');
req.query();
while (req.next()) {
req.location = req.requested_for.location;
req.setWorkflow(false);
req.update();
}
} catch (ex) {
gs.info(ex);
}
}
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
07-22-2025 06:52 PM
Hi @SN2024
Consider create an OnChange Client Script
- Table: sc_request
- Type: onChange
- Field name: requested_for
- script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Get the location of the selected requested_for user
var ga = new GlideAjax('GetUserLocation');
ga.addParam('sysparm_name', 'getLocation');
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('location', response);
}
});
}
Now Create the Script Include:
• Name: GetUserLocation
• Client Callable: (Check this!)
• Script:
var GetUserLocation = Class.create();
GetUserLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocation: function() {
var userID = this.getParameter('sysparm_user');
var userGR = new GlideRecord('sys_user');
if (userGR.get(userID)) {
return userGR.location.toString();
}
return '';
}
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 06:55 PM
Have you considered running a simple background script
var gr = new GlideRecord('sc_request');
gr.addNullQuery('location') //Only where locaiton is currently empty
gr.query();
var count = 0;
while(gr.next()) {
var user = new GlideRecrod('sys_user');
if (user.get(gr.requested_for)) {
if (user.location) {
gr.location = user.location;
gr.update();
count++;
}
}
}
gs.print('Updated ' + count + ' sc_request records with location from requested_for user.');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 06:57 PM
Hi @SN2024 Try using onchange client script and script include for it..
Regards,
Prasanna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2025 07:02 PM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('requested_for', function(user) {
g_form.setValue('location', user.location); // use .location for reference field
});
}
✔️ If this solves your issue, please mark it as Correct.
✔️ If you found it helpful, please mark it as Helpful.
—
Shubham Jain