- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 10:56 AM
I create a script that insert new records in a table. One of table fields is a Choice List. How can I check on insert if the desired value for Choice List field exists, and create a new Choice Option if not ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 11:37 AM
Hope below script will help you !!!
var gr=new GlideRecord('sys_choice');
gr.addQuery('name',"table_name");
gr.addQuery('element',"column_name");
gr.addQuery('value',"value");
gr.query();
if(!gr.next())
{
var gr1=new GlideRecord('sys_choice');
gr1.initialize();
gr1.name="table_name";
gr1.element="column_name";
gr1.value="value";
gr1.label="label";
gr1.language="En";
gr1.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 11:20 AM
You should be able to query the sys_choice table (all choices in the system are in that table) for the record corresponding to the specific table, element, and value you're looking for and create it if your query doesn't return any records.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 11:37 AM
Hope below script will help you !!!
var gr=new GlideRecord('sys_choice');
gr.addQuery('name',"table_name");
gr.addQuery('element',"column_name");
gr.addQuery('value',"value");
gr.query();
if(!gr.next())
{
var gr1=new GlideRecord('sys_choice');
gr1.initialize();
gr1.name="table_name";
gr1.element="column_name";
gr1.value="value";
gr1.label="label";
gr1.language="En";
gr1.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2016 12:48 PM
Thank you very much to both of you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2021 07:54 AM
Hello,
Following to this post I'm sort of stuck. I have a choice list field domain with option (Science,Commerce & Arts) and for every domain I have 2 options which includes "other" as second option.
For an example if I'm choosing domain as science then I will have 2 options one is Biology and second is other. If I select "other" option the string field appear which asks me to enter my answer, once I enter it should go and check in choice table with dependent field science and if that choice dis not available then it should create a choice there.