Populate Requested for onchnage of Id and vice versa.

Samiksha2
Mega Sage

Hi All,

 

I have a requirement to show Id On change of Requested for.

I created a custom table u_custom_user and one field u_userid in that. I added a field in the user table name Id which is referencing to the u_custom_user
In the catalog form there are two variable Requested for(reference- sys_user) and Id(Lookup select box- sys_user, lookup field value- Id).

On change of Requested for Id should populate and on change of Id Requested for should populate.

 

Please help in this.

 

Thanks!

Samiksha 

 

4 REPLIES 4

Harish Bainsla
Tera Sage
Tera Sage

you can use script include for this

 

Hi @Harish Bainsla 

I tried but it is not working.

Script Include

var requestor_details = Class.create();
requestor_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getCustomerId: function() {
        var user = this.getParameter('sysparm_user');
        var results = "";
        var customer = new GlideRecord("u_custom_user");
        customer.addQuery('u_userid', user);
		customer.query();
		if (customer.next()){
			var cus= cost.u_user_id;
			var users = new GlideRecord('sys_user');
			users.addEncodedQuery("user_nameSTARTSWITH" + cus);
			users.query();
			if (users.next()){
				results = users.u_idss.getDisplayValue();
			}
			return JSON.stringify(results);
		}

    },
    type: 'requestor_details'
});

Client script

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

    var user_id = g_form.getValue('requested');
    var ga = new GlideAjax('requestor_details');
    ga.addParam('sysparm_name', 'getCustomerId'); 
    ga.addParam('sysparm_user', user_id); 
    ga.getXML(EmployeeDetailsLookup); 
}

function EmployeeDetailsLookup(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var result = JSON.parse(answer);
	alert(result);
    g_form.setValue('id', result);
}

I am getting null on alert.

 

HarishBainsla_0-1692183375523.png

cost means because it does not get any value

 

Hi @Harish Bainsla,

I corrected the var value as  customer. Still null is coming.