Handling “None” Choice in Catalog Item Select Box Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 02:55 AM - edited 03-29-2024 04:53 AM
Hello everyone,
I’m working with a catalog item that includes a select box type variable. Unfortunately, this variable does not have a “None” choice(requester dont want to include None as a choice on catalog items but they need it on Native UI). However, in the native UI of the cmdb_ci_appl table, there is an option for “None.”
My challenge is to create an onChange client script that ensures the following behavior:
- If the backend choice is “None,” the catalog item should display as blank (no selection).
- Currently, it defaults to selecting the first variable.
Any guidance or suggestions on achieving this would be greatly appreciated!
Thank you in advance for your help.
Onchange client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gainst = new GlideAjax('global.testing123');
gainst.addParam('sysparm_name', 'getcatupdateform');
gainst.addParam('sysparm_catupdte', g_form.getValue('appl_name'));
gainst.getXML(catupdateResponse);
function catupdateResponse(response) {
var answer1 = response.responseXML.documentElement.getAttribute("answer");
var data = JSON.parse(answer1);
//var data1 = JSON.stringify(data);
// alert(data1);
if (data.sur1 == null) {
g_form.setValue('var1', '', '');
} else {
g_form.setValue('var1', '', '');
g_form.setValue('var1', data.sur1, data.sur2);
//Type appropriate comment here, and begin script below
}
}
}
var testing123 = Class.create();
testing123.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getcatupdateform: function() {
var obj = {};
var par = this.getParameter("sysparm_catupdte");
//gs.addInfoMessage("sysparm_catupdte" + par);
var gr = new GlideRecord("cmdb_ci_appl");
if (gr.get(par)) {
obj.sur1 = gr.getValue('u_string_1');
obj.sur2 = gr.getDisplayValue('u_string_1');
var data = JSON.stringify(obj);
return data;
}
},
type: 'testing123'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2024 09:10 PM
@Community Alums
Apply alert on 'data' and see what are you getting in to that also put one alert in else part to see if it going inside else.
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks