Referencing a value from a referenced record

phil34
Tera Expert

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

find_real_file.png

I am updating the location using a catalog Client Script and this is working for the location field just fine

find_real_file.png

 

How do I get the Division to display the value held in the location table reference above?

Hope that makes sense

 

5 REPLIES 5

Muhammad Khan
Mega Sage
Mega Sage

Hi,

 

You can only dot-walk to 1-level using getReference(). If you want to go further then you would need to use GlideAjax.

Upender Kumar
Mega Sage

Mahendra RC
Mega Sage

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

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