auto populating fields from a reference in UI Page

yundlu316
Kilo Guru

I created a UI Page that incorporates a reference field using <g:ui_reference>.   Field 13 in the below screenshot uses this code:  

<label> 13. Name of family member $[SP]<i>(last, first, middle initial)</i></label>

<g:ui_reference name="family_member_1" id="family_member_1" table="hr_beneficiary" query="active=true" completer="AJAXTableCompleter" columns="employee; beneficiary_contact.relationship" />

find_real_file.png

When a user chooses a beneficiary from the reference field, I want 14. SSN and 15. DOB to autopopulate.   If this was a regular Record Producer, I would have written an onChange client script on 13. Name of family member, but since this form is coded as a UI Page, I can't utilize g_form.   How would I go about autopopulating fields based on the reference chosen?

Thanks!

1 ACCEPTED SOLUTION

You will have to add toString() to all the elements in the object as shown below. Copy the function as is in to your script include and you are good to go



getDetails: function(){


  var obj = {};


  var usr= new GlideRecord('hr_beneficiary');


  usr.addQuery('employee',gs.getUserID());


  usr.addQuery('sys_id',this.getParameter('sysparm_id'));


  usr.query();


  if(usr.next()){


  var name = usr.beneficiary_contact.name.toString();


  var arr2 = name.split(" ") ;


  var name2 = arr2[1] + ", " + arr2[0];


  obj.beneficiary_name = name2;


  obj.beneficiary_ssn = usr.getValue('ssn');


  obj.beneficiary_date_of_birth = usr.getValue('date_of_birth');


  obj.beneficiary_email = usr.beneficiary_contact.email.toString();


  obj.beneficiary_mobile=usr.beneficiary_contact.mobile_phone.toString();


  obj.beneficiary_relationship=usr.beneficiary_contact.relationship.toString();


  obj.beneficiary_percentage=usr.getValue('percentage');


  obj.beneficiary_address=usr.beneficiary_contact.address.toString();


  }


  var data = JSON.stringify(obj);


  return data;


  },


View solution in original post

26 REPLIES 26

thanks abhinay, yea I think GlideAjax is the way to go, can you help me transform the above code into GlideAjax?   I tried following the examples in the Wiki without any luck.  


Here is you script include code


Name: GetBeneficiaryDetails


Client callable:true


Script:


var GetBeneficiaryDetails = Class.create();


GetBeneficiaryDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  getDetails: function(){


  var obj = {};


  var usr= new GlideRecord('hr_beneficiary');


  usr.addQuery('employee',gs.getUserID());


  usr.addQuery('sys_id',this.getParameter('sysparm_id'));


  usr.query();


  if(usr.next()){


  var name = usr.beneficiary_contact.name;


  var arr2 = name.split(" ") ;


  var name2 = arr2[2] + ", " + arr2[1];


  obj.beneficiary_name = name2;


  obj.beneficiary_ssn = usr.getValue('ssn');


  obj.beneficiary_date_of_birth = usr.getValue('date_of_birth');


  obj.beneficiary_email = usr.beneficiary_contact.email;


  obj.beneficiary_mobile=usr.beneficiary_contact.mobile_phone;


  obj.beneficiary_relationship=usr.beneficiary_contact.relationship;


  obj.beneficiary_percentage=usr.getValue('percentage');


  obj.beneficiary_address=usr.beneficiary_contact.address;


  }


  var data = JSON.stringify(obj);


  return data;


  },


  type: 'GetBeneficiaryDetails'


});




Client script for UI page:


var ga = new GlideAjax('GetBeneficiaryDetails');


ga.addParam('sysparm_name','getDetails');


ga.addParam('sysparm_id', $('family_member_1').value);


ga.getXML(CallBack);



function CallBack(response) {


    var answer = response.responseXML.documentElement.getAttribute("answer");


    var rec=JSON.parse(answer);


  $('fm1_ssn').value=rec.beneficiary_ssn;


  $('fm1_dob').value= rec.beneficiary_date_of_birth;


}


THANKS abhinay!   When I run it, I get the following error:



AbstractAjaxProcessor undefined, maybe missing global qualifier


Hi Abhinay,



  I have tapped all the threads for this same issue but I have a different scenario.   I have a UI page created in Catalog form with Group Role Variable.



  This Group Role( UI Page) should list the values based on the Classification Field from the form. So basically, I have to query the value of the classification and when the UI page Group Role field( reference) is selected. The result should show only based on the selection I made above in my classification field.



    To brief, I have to use onchange client script on the variable and then apply the value in UI Page Variable referencing the Catalog Variable..



Thanks


Shankar


Abhinay Erra
Giga Sage

Are you in a scoped application?