- 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:20 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var changeRequest = g_form.getValue('change_request_id');
if (changeRequest) {
g_form.getReference('change_request_id', callBack, 'change_request');
}
}
function callBack(reference) {
if (reference) {
g_form.setValue('state_of_change_request', reference.getValue('state'));
}
}
You can check hope this helps.
You can give thumps up, if there is any issue can tag me.
Thanks
Abi
Thanks
Abi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 04:30 AM
It is still fetching the value as 1,2 not fetching the label
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 04:39 AM - edited 02-22-2023 04:40 AM
Create a new script include
var GetStateOfChangeRequest = Class.create();
GetStateOfChangeRequest.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getState: function() {
var gr = new GlideRecord('change_request');
gr.addQuery('number', this.getParameter('sysparm_change_request_id'));
gr.query();
if (gr.next()) {
return gr.state.getDisplayValue();
}
return '';
},
type: 'GetStateOfChangeRequest'
});
And on onChange function you can write this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('GetStateOfChangeRequest');
ga.addParam('sysparm_name', 'getState');
ga.addParam('sysparm_change_request_id', newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue('state_of_change_request', answer);
});
}
Hope this works
Thanks
Abi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2023 11:16 PM
It is still not fetching the state values