how to determine if it's a prod or dev environment in servicenow flow designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 04:48 AM
Hi all experts
I am new to servicenow development, i have requirement, create sub-flow and check current instance value (true/false) from system property.
{
"dev1": { "value": "true" },
"dev2": { "value": "false" },
"prod": { "value": "false" },
"test": { "value": "false" }
}
- I have created script action and checking in my sub-flow but not working as expected. Could you please help me out here how to do this? (if possible please provide the steps to create this)
var env = gs.getProperty('glide.servlet.uri'); // Get the current instance's URL
var envKey = env.substring(env.indexOf('//') + 2, env.indexOf('.'));
var _available = JSON.parse(gs.getProperty('instance_available'));
if (!_available[envKey] || _available[envKey].value === "false") {
return false; // Exit subflow if instance is not available
}
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 11:37 PM - edited 08-26-2024 11:38 PM
@learner625 Please find my implementation steps in retrieving the instance name and routing it accordingly.
1. Create a flow variable
2. Set the flow variable. By default, all the instances will have this property to fetch the instance name.
3. Use this variable to identify the instance and route it accordingly.
For e.g. When the instance matches it updates the comments on the record as,
When the instance doesn't match, it updates the comments on the record as,
For your scenarios, you need to use "If, Else-If" conditions to achieve your requirement.
Sujatha V.M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 12:37 AM
Hi @learner625
We can define a flow variable, then use your script to set value for the variable. After that, we can use the flow variable with If Else condition in next steps.
Sample script
var instanceAvailable = JSON.parse(gs.getProperty('instance_available'));
var instanceName = gs.getProperty('instance_name');
return instanceAvailable[instanceName].value;
My property:
{
"dev1": { "value": "true" },
"dev2": { "value": "false" },
"prod": { "value": "false" },
"test": { "value": "false" },
"dev183165": { "value": "true"}
}
Sample steps:
Cheers,
Tai Vu