- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 02:49 AM
Hi,
I have two selectbox variables and one reference variable to autopopulate, but one selectbox is not displaying. Kindly help.
GlideAJAX
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == "") {
g_form.setValue('current_primary_approver', "");
g_form.setValue('share_type', "");
g_form.setValue('protocol_type_new', "");
} else {
alert(g_form.getValue('protocol_type_new'));
var ga = new GlideAjax('populate_modify_network');
ga.addParam('sysparm_name', 'get_modify');
ga.addParam('sysparm_share_path', newValue);
ga.getXML(callBackFunction);
function callBackFunction(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var op = JSON.parse(answer);
g_form.addInfoMessage(answer);
g_form.setValue('current_primary_approver', op.approver);
g_form.setValue('share_type', op.type);
g_form.setValue('protocol_type_new', op.protocol);
}
}
}
ScriptInclude
var populate_modify_network = Class.create();
populate_modify_network.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_modify : function()
{
var path = this.getParameter('sysparm_share_path');
var values = {};
var gr = new GlideRecord('u_cmdb_ci_file_share');
gr.addQuery('sys_id',path);
gr.query();
if(gr.next())
{
values.approver = gr.managed_by.toString();
values.type = gr.u_type.getDisplayValue();
values.protocol = gr.u_protocol.getDisplayValue();
}
return JSON.stringify(values);
},
type: 'populate_modify_network'
});
Even though Employment Center showing up as the correct protocol, it is not getting into the variable.
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 04:47 AM
you should set either of those 2 choice values.
check the value in server side and set it accordingly
var populate_modify_network = Class.create();
populate_modify_network.prototype = Object.extendsObject(AbstractAjaxProcessor, {
get_modify: function() {
var path = this.getParameter('sysparm_share_path');
var values = {};
var gr = new GlideRecord('u_cmdb_ci_file_share');
gr.addQuery('sys_id', path);
gr.query();
if (gr.next()) {
values.approver = gr.managed_by.toString();
values.type = gr.u_type.getDisplayValue();
if (gr.u_protocol.toString() == 'Windows Only')
values.protocol = 'windows';
else
values.protocol = 'multiprotocol';
}
return JSON.stringify(values);
},
type: 'populate_modify_network'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 05:20 AM
are you sure you are comparing the correct value here from the field u_protocol?
use this if you are comparing the choice label
if (grec.u_protocol.getDisplayValue() == 'Windows Only')
arrayss.protocol_type = 'windows';
else
arrayss.protocol_type = 'multiprotocol';
use this if you are comparing the choice value
if (grec.u_protocol.toString() == 'windows choice value here from field')
arrayss.protocol_type = 'windows';
else
arrayss.protocol_type = 'multiprotocol';
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 05:38 AM
Did you accidentally marked your own response as correct?
Would you mind marking my response as correct if it worked for you?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 05:42 AM - edited 02-20-2025 05:55 AM
This worked for me. In the glideRecord, i have two choices in the dictionary for protocol type. So, I used the corresponding values in the dictionary and it worked.
var populate_modify_network_class = Class.create();
populate_modify_network_class.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populate_modify_network_function: function() {
var obj = this.getParameter('sysparm_share');
var arrayss = {};
var grec = new GlideRecord('u_cmdb_ci_file_share');
grec.addQuery('sys_id', obj);
grec.query();
if (grec.next()) {
arrayss.primary = grec.managed_by.toString();
arrayss.shareType = grec.u_type.getDisplayValue();
//if condition for protocol
if (grec.u_protocol.toString() == 'windows_only')
arrayss.protocol_type = 'windows';
else
arrayss.protocol_type = 'multiprotocol';
}
return JSON.stringify(arrayss);
},
type: 'populate_modify_network_class'
});
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 05:45 AM
Did you accidentally marked your own response as correct?
Would you mind marking my response as correct if it worked for you and I shared the approach to compare using IF ELSE
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2025 05:56 AM - edited 02-20-2025 05:59 AM
Hi @Ankur Bawiskar,
I never intend to my response as correct. Is there a way I can correct it. I corrected it now. Thank You.
Regards
Suman P.