- 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-20-2015 04:44 AM
Hi Rick,
Glide record is not supported / allowed in client side scripts in scoped apps. You have to use GlideAjax to fulfill the requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 04:46 AM
You can refer the below thread for more info.
Error using GlideRecord in a scoped application in Fuji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 04:40 AM
Ok so I guess that this error is because GlideRecord is not supported / allowed in client side scripts in scoped app. So we will have to do the AJAX call solution.
So the code you should do is something like this:
- 1. On change client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('GetCustomerData');
ga.addParam('sysparm_field','u_reference_1');
ga.addParam('sysparm_user_id',newValue);
ga.getXML(DoSomething);
function DoSomething(response) {
var company = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('company',company);
}
}
- 2. Create a Script include, must be client callable and the name should be GetCustomerData [It should match the name used on GlideAjax constructor].
var GetCustomerData = Class.create();
GetCustomerData.prototype = Object.extendsObject(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')];
}
});
You can use GetCustomerData to get any data from the customer record, the only thing you should do is change the column on ga.addParam();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 04:54 AM
Only creating the CS and SI gives me this error:
AbstractAjaxProcessor undefined, maybe missing global qualifier
Antonio Vegue Martinpintado wrote:
[...] the only thing you should do is change the column on ga.addParam();
I assume you mean these?
ga.addParam('sysparm_field','u_reference_1');
ga.addParam('sysparm_user_id',newValue);
What exactly needs to be changed there? And to which colomn?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2015 05:06 AM
Sorry I mixed up a couple of thigs. On the client script you should use:
ga.addParam('sysparm_name','getFieldValue');
ga.addParam('sysparm_field','u_reference_1');
ga.addParam('sysparm_user_id',newValue);
I hope this finally works