
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 07:05 AM
I have a workflow set up for a catalog item and I want to include an IF Statement in the workflow that will check whether a single text field contains/starts with the following strings: "10.", "161.", "172."
To summarize, the script is supposed to check if the entered IP address in the variable begins with a 10. or a 161. or a 172. address.
Variable Name: source_ip
I tried scripting it out but I have no idea where to start as I want it to specifically check that the string BEGINS with the above numbers. I cannot use a CONTAINS condition because an IP of x.x.10.x would still trigger the statement.
Here's a picture of the proposed script that I've wrote up, can anybody provide any recommendations?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 10:24 AM
What type is the "source_ip" catalog variable?
You can force your script variable "sourceIP" to a string with the following:
var sourceIP = current.variables.source_ip.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 08:31 AM
Hi LDN1622,
If you want to check if string starts with "10.", "161.", "172."
Please use the below code and let me know if you face any issue (since I didn't actually tried it myself):
var sourceIP = current.variables.source_ip;
if(sourceIP.startsWith("10.") || sourceIP.startsWith("161.") || sourceIP.startsWith("172.")) {
return 'yes';
}
return 'no';
if you want to check if string field contains 10.", "161." or "172."
var sourceIP = current.variables.source_ip;
if(sourceIP.indexOf("10.") >= 0 || sourceIP.indexOf("161.") >= 0 || sourceIP.indexOf("172.") >= 0) {
return 'yes';
}
return 'no';
Please let me know if this is not what you are looking for.
Please mark this correct, if it resolves you problem.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 10:46 AM
Use current.variables.source_ip.toString(); and try ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 11:15 AM
Working now, thank you for the assistance.