
- 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:49 AM
Hi
You can use something like this
function ifScript(){
var sourceIP = current.variables.source_ip;
if(sourceIP.indexOf("10.") == 0 || sourceIP.indexOf("161.") == 0 || sourceIP.indexOf("172.") == 0) {
return 'yes';
}
return 'no';
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 09:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2018 10:16 AM
Can you try to add
var sourceIP = "";
sourceIP = current.variables.source_ip;
- 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 11:14 AM