- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2015 07:45 AM
How can I get a value from a Reference field to populate a String field via an OnChange client script (for a Catalog Item)? Right now, all I can get is the Sys_ID. The field needs to get populated initially with the cost_center field, based on the logged in under, but after that it may need to be manually changed (to a non-reference value).
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2015 05:53 AM
This will work
Script Include:
var UserDetailsAjax = Class.create();
UserDetailsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCostCenterDetails: function()
{
var getUserCostDetails = new GlideRecord('sys_user');
if(getUserCostDetails.get(this.getParameter('sysparm_requested_for')))
{
return getUserCostDetails.cost_center.getDisplayValue();
}
}
});
Client script
var getCost = new GlideAjax('UserDetailsAjax');
getCost.addParam('sysparm_name','getCostCenterDetails');
getCost.addParam('sysparm_requested_for',newValue);
getCost.getXML(setCostCenter);
function setCostCenter(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('cost_center', answer);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2015 07:50 AM
Hi Jued
Try this
g_form.getDisplayBox('reference field').value;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2015 05:35 AM
How would that play into this OnChange script (or is this the wrong approach entirely)? I tried using it in a couple different ways but without success.
function onChange(control, oldValue, newValue, isLoading) {
if(newValue != ""){
var reqFor2 = g_form.getReference('requested_for');
// g_form.getDisplayBox('reference field').value;
g_form.setValue('cost_center', reqFor2.cost_center);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2015 07:10 AM
A screenshot would help us to see your current setup and respond accordingly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2015 07:21 AM