Choice has to be created on fly of data load in global domain, but is setting as user's domain

GowriManohS
Tera Contributor

We are validating if the choice exist on before script, if doesn't exist create choice it in global domain. As global domain is the default value and not actual record in domain table, so it is not setting as global domain through scripts when user runs the script from different domains.  

 

Only if user is in global it sets as domain as global.

 

Choices are created and set domain as per user's domain, even though we default to "global" in the script. setWorkflow(false) also didn't help.

 

Kindly let me know if anyone have a solution for this?

1 REPLY 1

SIVASANKARIS
Mega Guru

Hi @GowriManohS ,

 

What you’re facing is how ServiceNow handles domain separation when creating records via script.

Here’s the key part:

  • When a user runs a script, ServiceNow automatically sets the new record’s domain to the user’s current session domain (not always Global).

  • Because Global isn’t a real domain record in the sys_domain table, scripts trying to force a “global” domain don’t always work when the user is in a different domain.

  • That’s why:

    • If the user is in Global, the choice gets created in Global

    • If the user is in another domain, the choice gets created in that domain instead

So even if your script tries to set sys_domain = global, the system still respects the user’s current session domain first.

 

What This Means Practically

  • You can’t reliably insert a sys_choice record in Global from a script running in another domain without switching context.

  • A common workaround:

    • Run your choice creation script in the Global domain session (e.g., background script when logged into Global)

    • Or manually adjust the sys_domain after record creation

You can refer the below articles

https://www.servicenow.com/community/developer-forum/configuring-choice-lists-in-domains/m-p/1916667...

https://www.servicenow.com/docs/bundle/xanadu-platform-security/page/administer/company-and-domain-s...

https://www.servicenow.com/community/international-localization/recent-changes-for-sys-choice-entrie...

 

IF THIS IS PLEASE MARK MY ANSWER AS HELPFUL AND ACCEPT MY SOLUTION...