- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
I have the below script include script which retreives a list of locations based on the Requested by user on a catalog form.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @harshamovva ,
I noticed one issue in your updated Script Include. In the requested_for block, you're querying nusr, but your condition is still checking if (usr.next()) instead of if (nusr.next()). Because of that, the second query never processes correctly.
Also, after updating either the Requested By or Requested For variable, make sure the Location reference field is refreshed (for example, using g_form.clearValue('location') and g_form.refreshReference('location') in an onChange Catalog Client Script).
Otherwise, the reference qualifier may not be re-evaluated automatically.
If you've already done that and it's still not working, please share the onChange Catalog Client Script you're using for the Requested For variable.
Sachin Narayanasamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @harshamovva ,
I noticed one issue in your updated Script Include. In the requested_for block, you're querying nusr, but your condition is still checking if (usr.next()) instead of if (nusr.next()). Because of that, the second query never processes correctly.
Also, after updating either the Requested By or Requested For variable, make sure the Location reference field is refreshed (for example, using g_form.clearValue('location') and g_form.refreshReference('location') in an onChange Catalog Client Script).
Otherwise, the reference qualifier may not be re-evaluated automatically.
If you've already done that and it's still not working, please share the onChange Catalog Client Script you're using for the Requested For variable.
Sachin Narayanasamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Thank you for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Anytime! @harshamovva ✨
Sachin Narayanasamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago - last edited 3 hours ago
Hi @harshamovva
Can you try this. If it works - update it as per your requirement:
- Update Refrence Qualifier of Location Reference variable
- Right-click the Location field on your form and click Configure Dictionary.
- Update the Reference Qualifier
- In the Reference qual field, enter the following JavaScript to filter locations associated with the selected user's location:
javascript: 'sys_idIN' + new YourScriptIncludeName().getLocations(current.variables.u_requested_by);
2. Create the Script Include
- Navigate to System Definition > Script Includes and create a new record.
- Name it: GetUserLocations
- Check Client callable.
var GetUserLocations = Class.create(userId);
GetUserLocations.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getLocationData: function() {
var userGr = new GlideRecord('sys_user');
if (userGr.get(userId)) {
return userGr.location;
}
return '';
},
type: 'GetUserLocations'
});
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti