Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

client script auto fill variable value email

Jeff W NZAO B
Mega Guru

Hello,

Please i want to auto fill a variable field which is a single line text depending on a referenced variable field. I created a script include and then a client script. 

script include:

getFunctionEmail: function() {
        try {


            var varBeneficiary = this.getParameter('sysparm_userid');

            var grUser = new GlideRecord('sys_user');
            if (grUser.get(varBeneficiary)) {
                var json = new JSON();
                return json.encode(grUser.getDisplayValue('email'));
            }
        } catch (e) {}
    }

 

client script :

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	
	var ga = new GlideAjax('IncludeName');
		ga.addParam('sysparm_name', 'getFunctionEmail');
		ga.addParam('sysparm_userid', newValue.toString());
		ga.getXML(populateEmail);
  
	function populateEmail(response) {
		 
		  var answer = response.responseXML.documentElement.getAttribute("answer");
	

			
			g_form.setValue("mail_beneficiary", answer.toString().replace(/['"]+/g, ''));
			
		   
	}

	
}

 

1 REPLY 1

Sandeep Rajput
Tera Patron

@Jeff W NZAO B Please update your script include method as follows and see if it works.

 

getFunctionEmail: function() {
        try {
            var varBeneficiary = this.getParameter('sysparm_userid');
            var grUser = new GlideRecord('sys_user');
            if (grUser.get(varBeneficiary)) {               
                return grUser.getValue('email');
            }
        } catch (e) {}
    }