- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 04:37 AM
Hi everyone,
I want to get the sys_id of a choice in a select box type variable and compare it to the value set on a property, and if it's equal it makes some fields mandatory and visible.
I have a catalog client script and a script include but it's not working.
I will put the property name and the scripts below:
Property name : Payroll_Internal
Catalog Client Script and Script Include function are below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var openedFor = g_form.getValue('opened_for');
var subjectPerson = g_form.getValue('subject_person');
var selectBoxValue = g_form.getValue('please_choose_the_desired_subcategory');
var user = g_user.userID;
var ga = new GlideAjax('AskHR_UtilitiesAJAX');
ga.addParam('sysparm_name', "getProperties");
ga.getXML(getPropertiesSysID);
function getPropertiesSysID(response) {
var propertiesID = response.responseXML.documentElement.getAttribute('answer')
var jsonstring = JSON.parse(propertiesID);
if (selectBoxValue === jsonstring.payrollInternal) {
g_form.setValue('subject_person', user);
g_form.setValue('opened_for', user);
g_form.setReadOnly('opened_for', true);
g_form.setReadOnly('subject_person', true);
g_form.setVisible('subject_person', false);
} else {
g_form.setReadOnly('subject_person', false);
g_form.setReadOnly('opened_for', false);
g_form.setMandatory('subject_person', true);
g_form.setVisible('subject_person', true);
}
}
}
getProperties: function() {
var obj = {};
obj.payrollInternal = gs.getProperty('Payroll_Internal');
return JSON.stringify(obj);
},
If you have any idea please let me know!
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 04:51 AM
Hello @rafas_2703 ,
To get the sys_id of the choice you need to glide Query the sys_choice table then only you can get sys_id.
In the same script include you can gliderecord to sys_choice table and return the sys_id to client script and do the check.
Thank you,
Omkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2023 04:51 AM
Hello @rafas_2703 ,
To get the sys_id of the choice you need to glide Query the sys_choice table then only you can get sys_id.
In the same script include you can gliderecord to sys_choice table and return the sys_id to client script and do the check.
Thank you,
Omkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 07:12 PM - edited 03-13-2024 07:18 PM
Do not work your logic around sys_id of a sys_choice field as sys_choice entries work with "value". Any modification to the sys_choice list will purge the existing records and new records will created resulting in a new sys_id. So your logic with hardcoded sys_id of sys_choice list may fail.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0656146