- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 04:22 AM
Hi there,
I'm figuring out the best way to do this..
In my form, I have 2 fields: caller and hospital.
Caller refers to the users table, Hospital refers to the company table.
My goal is: whenever I populate the caller field, the system needs to lookup the hospital of that caller and needs to auto-populate that.
Example: Customer X is part of Hospital X. Customer X is the caller so will be populated in the caller field. The system recognizes that Customer X is part of Hospital X so hospital will be Hospital X.
Hope you guys can help me out!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2015 06:53 AM
We got it working!
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetCustomerData');
ga.addParam('sysparm_name','getFieldValue');
ga.addParam('sysparm_field','u_reference_1');
ga.addParam('sysparm_user_id', g_form.getValue('caller'));
ga.getXML(DoSomething);
function DoSomething(response) {
var company = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('company',company);
}
}
Script include:
var GetCustomerData = Class.create();
GetCustomerData.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getFieldValue: function() {
var user = new GlideRecord('x_medt2_ihs_customers');
user.get(this.getParameter('sysparm_user_id'));
if(! user.sys_id){
return false;
}
return user[this.getParameter('sysparm_field')];
}
});
Thanks everybody for the great help on this!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2015 10:23 AM
This code should work
In mine I made a silly mistakes while passing field name to getReference function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 01:54 AM
Antonio Vegue Martinpintado wrote:
Hi community!
To populate that field when you are filling the form, you will need a client script on change. This would be the code:
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('caller_id', getHospital); // getHospital is our callback function
}
function getHospital(caller) { //reference is passed into callback as first arguments
g_form.setValue('company',caller.u_hospital) //Im guessing that the column name of the field Hospital on Customer form is u_hopital. Check the dicctionary to be sure!
}
I hope it helps!
Regards,
Antonio.
Thanks Antonio,
I had to make some adjustments, but this is what I got so far:
function onChange(control, oldValue, newValue, isLoading) {
var caller_id = g_form.getReference('caller', getHospital);
}
function getHospital(caller_id) {
alert(caller_id.name);
alert(caller_id.u_reference_1);
g_form.setValue('company',caller_id.u_reference_1);
}
This outputs:
"Customer X" (which is the customer I filled in at caller)
"undefined" (which should be "Hospital X")....

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 01:57 AM
Hi Rick,
Can you please confirm if the field column name is "u_reference_1". Can you please paste screenshot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 02:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 02:05 AM