sn_ws.RESTMessageV2 API to verify which environment it is

NagE
Tera Contributor

Future State: As a ServiceNow developer, I'd like for business rule sn_ws.RESTMessageV2  API executions to stay within their environment.

 

Ideally a business rule will have the intelligence to recognize what environment it's executing in, and then only act within that environment.

 

For example, if a business rule is making an outbound API call, it needs to know if it's in prod or nonprod, then call accordingly.


Please suggest the correct code to stay within the environment for all activities.

2 REPLIES 2

vaishali231
Tera Guru

hey @NagE 

 

A business rule can stay environment-safe by detecting the current instance (prod vs non-prod) using system properties, then dynamically choosing the correct sn_ws.RESTMessageV2 endpoint. Avoid hardcoding URLs; keep environment-specific values in properties or separate REST Message records so the same script works safely across all environments.

************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.

Regards
Vaishali Singh

miftikhar20
Kilo Patron

Hi @NagE,
ServiceNow doesn’t have a built-in Prod vs Non-Prod flag, but you can tell which instance the code is running on by reading the instance_name system property at runtime. Use:

var instanceName = gs.getProperty('instance_name');
Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.