Create choices from Global catItem for Custom Scoped App table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 12:57 PM
I am having an issue with creating choices from my script include for the Choice field on my custom table.
I have a Customer table with a field called event_name that is a choice type
I have a catItem that has a string field for the Event Name
When that field changes I have a GlideAjax Client script running a Script include to check if the name exists, if it does not exist create it. It is not creating the Choice in the Global Sys_Choice table.
If I go to sys_choice table from the Global Scope I do not see my table as a selection.
I have to change to my Scope and then I can se my table from sys_choice.
How can I do this???
I need to dynamically create choices if they do not already exist.
Thank you
CatItem is in Global
Catalog Client Script onChange of event_name variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('ChoiceAvailable');//x_bookings.ChoiceAvailable
ga.addParam('sysparm_name', 'checkChoice');
ga.addParam('sysparm_field', g_form.getValue("event_name").toString());
ga.addParam('sysparm_table', "x_bookings_reservation");
ga.addParam('sysparm_fieldLabel', g_form.getValue("event_name").toString());
ga.getXML(getresponse);
}
function getresponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
g_form.clearValue('event_name');
}
}
Script Include (Global) Accessible from All application scopes
var ChoiceAvailable = Class.create();
ChoiceAvailable.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkChoice: function() {
var event = this.getParameter('sysparm_field').toString();
// var table = this.getParameter('sysparm_table');
var table = 'x_bookings_reservation';
var label = this.getParameter('sysparm_fieldLabel').toString();
var elm = 'event_name';
//x_bookings.x_btig_bookings_reservation
gs.info("TRICIA these are the parms "+event +" table "+table+" label "+label+" elm"+elm);
This is in the Log TRICIA these are the parms Really me table x_bookings_reservation label Really me elmevent_namegs.info("TRICIA EVENT = " + event + " " + table);
var choicesGR = new GlideRecord('sys_choice');
choicesGR.addQuery('label', label);
choicesGR.addQuery('value', event);
choicesGR.addQuery('table', table);
choicesGR.addQuery('element', elm);
choicesGR.query();
gs.info("TRICIA CHOICES = " + choicesGR + " " + choicesGR.label);
if (!choicesGR.next()) {
var newChoice = new GlideRecord('sys_choice');
newChoice.newRecord();
newChoice.name = table;
newChoice.value = event;
newChoice.label = label;
newChoice.language = "en";
newChoice.element = elm;
newChoice.insert();
}
},
type: 'ChoiceAvailable'
});
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2022 10:00 PM
Hi,
Please check below configurations as well. Open Choice table configuration (dictionary) and allow create and Update (check highlighted checkbox). Also make sure A
If needed you may need to create some cross scope access policies.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 06:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2022 07:59 PM
Hi,
Please check sys_choice table and see if those choices are getting created in that table.
I tested your script on PDI from Global scope. After adding permissions on sys_choice table configuration it started working.
Also you can try creating same script include in Booking Application scope and make it accessible from all scope. You can call scoped app script include by using API name.
The scoped app script include would be having definition like below:
SI defination:
var ChoiceAvailable = Class.create();
ChoiceAvailable.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkChoice: function() {
//your logic
},
and call it in client script like:
var ga = new GlideAjax('x_bookings.ChoiceAvailable'); // use API name of Script include here
ga.addParam('sysparm_name', 'checkChoice');
Thanks,
Anil Lande
Thanks
Anil Lande