Referencing a value from a referenced record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 04:51 AM
Hi Community
In the below example I am trying to create a form that collects basic data about a selected user. I am able to display the data that is held in the user table, however, I also want to display the information in another table that is referenced so almost a nested result.
When I select a user there is a value in the user record called location and i can display that without any issue if I update the user the location will also update based on the value of the different user.
I need some help with the next field. Each location has a value for "Division" and I want to display that when the location updates.
My Form
I am updating the location using a catalog Client Script and this is working for the location field just fine
How do I get the Division to display the value held in the location table reference above?
Hope that makes sense
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 05:12 AM
Hi,
You can only dot-walk to 1-level using getReference(). If you want to go further then you would need to use GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 05:36 AM
Use GlideAjax.
Check the below link for GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-03-2022 08:13 AM
Hello Phil,
Please use the below scripts and replace the location and division field/variable name as per your instance:
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearValue('location'); // Clear value if newValue == ""
g_form.clearValue('division');
return;
}
if (newValue) {
var getAvaCnt = new GlideAjax('UserLocationDetails');
getAvaCnt.addParam('sysparm_name', 'getLocationData');
getAvaCnt.addParam('sysparm_employee', newValue);
getAvaCnt.getXMLAnswer(parseLocationResponse);
} else {
g_form.clearValue('location');
g_form.clearValue('division');
}
}
function parseLocationResponse(response) {
var answer = response.split(",");
g_form.setValue('location', answer[0]);
g_form.setValue('division', answer[1]);
}
Script Include:
var UserLocationDetails = Class.create();
UserLocationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateRequestedQuantity: function() {
var dataArray = [];
var userGuid = this.getParameter('sysparm_employee');
var userGR = new GlideRecord('userGuid');
if (userGR.get(MaterielType)) {
dataArray.push(userGR.getValue('location'));
dataArray.push(userGR.location.division.toString());
}
return dataArray.join(",");
}
type: 'UserLocationDetails'
});
Please mark my respsone as helpful/correct, if it answer your question.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2022 08:58 PM
Hello Phil,
Just wanted to check with you, if the above response answered your question. If yes, then please do close this thread/question by marking the appropriate response as correct.
If you still need any further help or guidance on this then please update those on this question.
Thanks