I'm working on a workflow, where the users have to input an array of IP addresses. The validation takes place in the user presentation, via Custom Validation, where the input IP address array is called and an action with the following code is executed:
var re = new RegExp("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$");
for each (IP in IPAdresses){
System.log("Checking IP: " + IP);
if (!IP.match(re)) { return "IP " + IP + " incorrect" } else { return null }
}
This works for a single input, with an array, only the top element (the last inserted) is checked in the user presentation. How should I modify the action, so that all input values are validated?
Thanks in advance...
Try the following:
var re = new RegExp("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$");
for each (IP in IPAdresses){
System.log("Checking IP: " + IP);
if (!IP.match(re)) { return "IP " + IP + " incorrect" }
}
return null;
In your code, you always return during the first iteration because you have return statements in both branches of the if condition. The solution is to move return null statement (successful validation result) after/outside of the cycle.
Try the following:
var re = new RegExp("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$");
for each (IP in IPAdresses){
System.log("Checking IP: " + IP);
if (!IP.match(re)) { return "IP " + IP + " incorrect" }
}
return null;
In your code, you always return during the first iteration because you have return statements in both branches of the if condition. The solution is to move return null statement (successful validation result) after/outside of the cycle.
Thanks, that resolved the issue! Pretty obvious when I look at it now:)
One last question... do you know if it is possible, to make the validation visible, when the workflow is imported into vRA 6.2? When I purposely enter invalid input values, there is a short loading time in the vRA input form, but no feedback about the values being wrong. When I accept the values, the vRA GUI the workflow give a success message, but the workflow just stays at the vRO user presentation.
I've got no possibility to edit the form in vRA, since it is presented during the workflow execution.