how to determine if it's a prod or dev environment in servicenow flow designer

learner625
Kilo Contributor

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.

2 REPLIES 2

Sujatha V M
Kilo Patron
Kilo Patron

@learner625 Please find my implementation steps in retrieving the instance name and routing it accordingly. 

 

1.  Create a flow variable 

SujathaVM_0-1724740292893.png

SujathaVM_1-1724740324326.png

 

2. Set the flow variable. By default, all the instances will have this property to fetch the instance name. 

 

SujathaVM_2-1724740367321.png

 

3. Use this variable to identify the instance and route it accordingly. 

SujathaVM_4-1724740484399.png

 

For e.g. When the instance matches it updates the comments on the record as, 

SujathaVM_5-1724740606274.png

When the instance doesn't match, it updates the comments on the record as, 

SujathaVM_6-1724740646045.png

 

For your scenarios, you need to use "If, Else-If" conditions to achieve your requirement.

 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Tai Vu
Kilo Patron
Kilo Patron

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:

Timi_0-1724744207420.png

 

Cheers,

Tai Vu