available choices in choice list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 06:24 AM
Hi, I have field choice list on the form and some choices are removed from this field by the script. I want to review which choices are currently available. I want to get access to this field from background scripti using glide record. Can you help me with provideing any script template for this?
Thank you in advance! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 06:35 AM
Hi @Dominik1988 this kind of script you can write
var sysChoice = new GlideRecord("sys_choice");
sysChoice.addQuery("name", "incident");
sysChoice.addQuery("element", "state");
sysChoice.addQuery("language", "en");
sysChoice.orderBy("sequence");
sysChoice.query();
var table, element, label, infos = [];
while (sysChoice.next()) {
gs.print("sequence=" + sysChoice.sequence + "; value=" + sysChoice.value + "; label=" + sysChoice.label);
}
Please mark my answer Correct/Helpful
Regards,
Siddharam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 06:59 AM
You can use below example script to get the available choice
// Replace 'your_choice_list_field' with the actual choice list field name
var choiceListField = 'your_choice_list_field';
var gr = new GlideRecord('sys_choice');
gr.addQuery('your_condition_field', 'your_condition_value');
gr.query();
while (gr.next()) {
var availableChoices = gr.getElement('your_choice_list_field').getChoices();
gs.info('Record ' + gr.getDisplayValue() + ' - Available Choices: ' + availableChoices.join(', '));
}
Please mark my answer Correct/Helpful
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2024 07:48 AM
Actually exact problem is that I want to get all choice list values from scrachpad. my field is located on a form "device" and there is status field on this form. there is also client script which take all available state values from the scratchpad. I want to previewed those values and problem is that I need to do this from background cript.
My Idea is: