How to create new sys_choices from Record Producer Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 09:07 AM
I have a Record Producer with a String Field for Event Name
I need to check the sys_choice table to see if this is already a choice and if note create it in the sys_choice table.
Can someone share code on how to achieve this please.
Thank you
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 09:31 AM
Hi,
Best way would be to add an onchange client script that runs validates it
var ga = new GlideAjax('ChoiceAvailable');
ga.addParam('sysparm_name', 'ChoiceAvailable');
ga.addParam('sysparm_field', g_form.getValue("state"));
ga.addParam('sysparm_table', g_form.getValue("incident"));
ga.addParam('sysparm_fiedlLabel', g_form.getValue("new"));
ga.getXML(getresponse);
}
function getresponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer )
{
g_form.clearValue('<variable>')
}
}
Script include
var ChoiceAvailable = Class.create();
ChoiceAvailable.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkChopice: function() {
var fiedl = this.getParameter('sysparm_field');
var choice_label = this.getParameter('sysparm_fiedlLabel');
var field_table = this.getParameter('sysparm_table');
var gr = new GlideRecord('sys_choice');
gr.addQuery('element', fiedl);
gr.addQuery('label', choice_label);
gr.addQuery('name', field_table);
gr.query();
if (gr.hasNext()) {
return true;
}
},
type: 'ChoiceAvailable'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 09:52 AM
Anurug,
This looks like the way I was trying to build it.
Question I need to create a choice if one does not exist
so in the script include I would need to do an initialize?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:00 AM
This is just to validate whether this will be a unique entry or not.
Choice creation would happen on submission of record producer, that is what the record producer is for, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2022 10:35 AM
No this is to create a record on a custom table, the custom table has a choice field that if the choice does not already exist create it.
The variable is a string
so a user enters the event name
GA lookup to sys_choice
if it does not find the choice create it in the sys_choice table so on the table UI for the records it has the list of choices