VMware Cloud Community
St0ked56
Contributor
Contributor
Jump to solution

Validate a field before submitting

Hi,

I am trying to figure out how to validate a input param before the user is allowed submit.  What I want to do is compare the number of inputs into the array to a number variable.  So should validate this:

User input into array = 2 items

Number to verify from = 3 Items

Since numbers don't match an error should pop up. Similar to the "Allow same values" (Attached in picture).  I would want a pop up saying "Please add or subtract a value" or soemthing along those lines.

Can this be done?

Thank you

0 Kudos
1 Solution

Accepted Solutions
cdecanini_
VMware Employee
VMware Employee
Jump to solution

I forgot something:

To have an error message return a string instead of a boolean with something like that:

if (array.length != arrayLength ) {
     return "Invalid array length, length must be " + arrayLength ;
}   
return "";

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter

View solution in original post

0 Kudos
4 Replies
cdecanini_
VMware Employee
VMware Employee
Jump to solution

This can be done using the custom validation presentation property.

To make it easy create an action returning a boolean with an array and a number as input.

return (array.length == arrayLength);

Then use this action for the custom validation property.

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

I forgot something:

To have an error message return a string instead of a boolean with something like that:

if (array.length != arrayLength ) {
     return "Invalid array length, length must be " + arrayLength ;
}   
return "";

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
0 Kudos
St0ked56
Contributor
Contributor
Jump to solution

This is probably an error due to my lack of programming experience but this is what I have and the error i am getting.

I created the action "HostnameCheck"

I put 2 variables into this action.  One is an "array/string" and the other is a "number"

This is the script I put in (copied from above)

if (hostname.length != hostnameExpected ) {
     return "Invalid array length, length must be " + hostnameExpected ;
}   
return "";
After I created the action I went into the "Custom Validation" field and found my action and selected it.  This is what is put into the field:
GetAction("com.x.library.fullname","HostnameCheck").call(  , __NULL__ )
When I run the workflow I have this error at the bottom of the screen and unable to select "Submit" (See Pic)
This error stays there regardless if the array matches the number
0 Kudos
cdecanini_
VMware Employee
VMware Employee
Jump to solution

When you set the action for the validation property you need to set its parameters so it will create the string:

GetAction("com.x.library.fullname","HostnameCheck").call(#hostname  , #hostnameExpected);

From your string it seems you missed this step.

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter