- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 02:44 AM
I have a catalog item with 2 fields 'change request ID' and 'state of change request' . I have to fetch the state of change request based on change request ID. I have written onChange client script for this but it is not working properly.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var usr = g_form.getReference('change_request_id', callBack);
}
function callBack(usr)
{
g_form.setValue('state_of_change_request', usr.state);
}
It is fetching the value as follow -
In the choice table for state field the value is set as
It is fetching the value, but I want the label value to be populated on the form. How can I do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 11:28 PM
Hi Shalika,
Check below code-for glideAjax
This is code for client script-
var ga = new GlideAjax('DataHelperAJAX');
ga.addParam('sysparm_name','getState'); getState
ga.addParam('sysparm_if','change_id');
ga.getXML(populateCampus);
function populateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('campus',answer);
}
}
//--you have to create script include and function with name getState
//use this id in script include ,glide to change table ,get state value as-
write this code in script include function-
var id = this.getParameter('change_id');
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id',id);
gr.query();
if(gr.next()){
var state =gr.getDisplayValue('state');
}
return state;
Thanks,
Manjusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 03:38 AM
GlideReference will not work for getting the displayvalue. You need to use GlideAjax and get the state display value by state.getDisplayValue(); function.
Hope this helps.
Regards,
Shamma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 04:31 AM
how to write GlideAjax for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 11:28 PM
Hi Shalika,
Check below code-for glideAjax
This is code for client script-
var ga = new GlideAjax('DataHelperAJAX');
ga.addParam('sysparm_name','getState'); getState
ga.addParam('sysparm_if','change_id');
ga.getXML(populateCampus);
function populateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('campus',answer);
}
}
//--you have to create script include and function with name getState
//use this id in script include ,glide to change table ,get state value as-
write this code in script include function-
var id = this.getParameter('change_id');
var gr = new GlideRecord('change_request');
gr.addQuery('sys_id',id);
gr.query();
if(gr.next()){
var state =gr.getDisplayValue('state');
}
return state;
Thanks,
Manjusha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 11:34 PM
Hi Shilika,
in above code just update below line -
ga.addParam('sysparm_id',g_form.getValue('change_id')); -change_id is name of change id field present on catalog item ,if it is different just update it
var id = this.getParameter('sysparm_id');
Thanks,
Manjusha Bangale