auto populate a field based on a lookup select variable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2017 11:55 AM
I have a catalog item that uses a table (which includes two fields: Name and Cost).
In the catalog item form - the name fields is a "Lookup select box type", and the cost field is a single line text
I want to auto populate the value of the cost based on the name selected from the lookup select box.
My script is not working - this is what i have. NOTE: The script will work perfectly if I change the name field to a reference field - but the issue with that is the existing tickets will loose the value selected.
function onChange (control, oldValue, newValue, isLoading) {
if (newValue == '') {
g_form.setValue("sw_cost", "");
return;
}
var u_sw_apps = g_form.getReference('app_select',CallBack);
}
function CallBack(u_sw_apps) {
g_form.setValue("sw_cost", u_sw_apps.u_cost);
}
Any assistance is most appreciative.
Thank you,
Karen

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2017 04:02 AM
Thank you I will try this today.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 08:04 AM
Good day Shishir - I tried this and it is still not pulling back the value. Here is my script:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
//g_form.setValue('sw_cost', '');
return;
}
// Type appropriate comment here, and begin script below
var ga = new GlideAjax("getCostValue");
ga.addParam("syparm_name","getDetails");
ga.addParam("sysparm_app_select", g_form.getValue('app_select'));
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML.documentElement.getAttribute("answer");
g_form.setValue('sw_cost', answer);
}
}
Script Include:
var CostValue = Class.create();
getCostValue.prototype = Object.extendsObject (AbstractAjaxProcessor, {
getDetails: function() {
var newRecord = new GlideRecord ('sw_apps');
if(newRecord.addQuery ('sw_cost', this.getParameter('sysparm_app_select')))
return newRecord.getValue('sw_cost');
},
type: 'getCostValue'
});
Can you have a look at it?
Thanks,
Karen

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 08:21 AM
small correction in script include:
var getCostValue = Class.create();
getCostValue.prototype = Object.extendsObject (AbstractAjaxProcessor, {
getDetails: function() {
var newRecord = new GlideRecord ('sw_apps');
if(newRecord.addQuery ('sw_cost', this.getParameter('sysparm_app_select')))
return newRecord.getValue('sw_cost');
},
type: 'getCostValue'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 08:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2017 08:35 AM
okay, so based upon the app name (which is pointing to name field in u_sw_apps table) cost has to be auto populated? If yes, please try below script see if this helps.
var getCostValue = Class.create();
getCostValue.prototype = Object.extendsObject (AbstractAjaxProcessor, {
getDetails: function() {
var newRecord = new GlideRecord ('u_sw_apps');
if(newRecord.addQuery (this.getParameter('sysparm_app_select')))
return newRecord.getValue('u_cost'); //Please check the cost field name if that's correct or not?
},
type: 'getCostValue'
});