The CreatorCon Call for Content is officially open! Get started here.

How to insert sys_choice for scoped application element?

vimal11592
Tera Expert

Hi,

Can someone please suggest how to populate sys_choice for scoped application element.I have written following code:

  var setRecord = new GlideRecord("sys_choice");

  setRecord.initialize();

  setRecord.element = "x_12345_catalyst_bot_name";

  setRecord.inactive = "false";

  setRecord.label = reqBody.botName;

  setRecord.language = "en";

  setRecord.name = "incident";

  setRecord.value = reqBody.botName;

  setRecord.insert();

But data is not listed under choice.It is working in my local env but when I have installed the application on another instance it is not working.I think it is an application access related issue.But I am not getting any idea how to fix it.

Thanks,

Vimal

7 REPLIES 7

Daniel Draes
ServiceNow Employee
ServiceNow Employee

I don't get why you would do this via script. Is your app dynamically creating choice list values on incident table?


I would assume that the sys_choice table would not allow writing to it from outside global scope. Maybe you have modified this in your dev instance to make it work.


Hi Daniel,



Thanks for the reply!!



yes, I am trying to create choices dynamically on the incident table.


So if I understand it correctly, We can create dynamic choice from the application scope.




Thanks,


Vimal


Based on my baseline instance other scopes are not allowed to create entries in sys_choice by scripting:



screenshot.png


Trying to add a record via script triggered this message:



Security restricted: Execute operation on API 'GlideRecord.insert' from scope 'DD Test Scoped App' was granted and added to 'DD Test Scoped App' cross scope privileges


Security restricted: Create operation against 'sys_choice' from scope 'x_snc_dd_test_scop' has been refused due to the table's cross-scope access policy





Has anyone found a workaround for this?



It would be nice to bundle creation of choices into the application install.   For example, I have a scoped application that creates CI classes and uses Identification and Reconciliation to populate those classes.   I&R requires a Data Source string that is defined in the sys_choice table.   But the sys_choice table is global, so a fix script can't add a new data source.   At that point, I have to provide a separate update set for the user to load.   If they don't do it, the application is broken.



I vaguely remember some tips on bundling demo data with your scoped app.   But I'm pretty sure that only applies to data in the same scope.



Any advice?