Subscribe
pwl Former NetApp Employee
Accepted Solution

variable / expression syntax?

hi

is there a quick reference or cheat sheet on variable expression syntax somewhere ?

i know about things like      myVarSetting  =   'my_prefix_' + $userInput

but i recall there was something along the lines of :     myVarSetting  =  ( $userInput >= 500 ) ? "big" : "small"   

and also a way to give different labels to user input selection lists than the actual values, eg:   the select widget says  "Option 1", "Option 2", etc  but the variable gets set to "opt_1", "opt_2", etc.

i've trawled through the various guides & handouts but cant see anythign at this level of detail...

variable / expression syntax?

Hi Peter,

The answer to your question of "is there a quick reference or cheat sheet on variable expression / syntax somewhere", is 'Not Yet'.  It's one of the many things we're working on and trying to make sure is there.

That said, I wanted to provide a couple of examples for what you described.

Giving a go at describing the syntax:

     variable expression value ? <true value>:<not true value>

     variable      - whatever it is you're trying to evaluate

     expression - equals (==), greater than (>), less than (<), etc.

     ?                 - constant... part of the syntax

     <true value> - what value you want returned if the evaluation is true

     <not true value> - what value you want returned if the evauation is not true

Example1:

          $qtree1Name=="" ? " " :$qtree1Name

          This is an example where there is Optional user inputs.  The user input of 'qtree1Name' is requested, and if NULL, then the returned value is space. 

          If the 'qtree1Name' is anything other than NULL then the returned value is whatever was provided as input for 'qtree1Name'.

Example2:

     This is an example where a Return Node in a Find Chart is used to evaluate user inputs.  In this case the 'NumberofDataVols' user input is evaluated to be less than a certain value.  Depending on the evaluation the CreateVol2 and CreateVol3 variables are set to 'true' or 'false'.  These are being used to control whether the commands in the workflow are Enabled at the time of planning and execution.

Example3:

     This is an example of using a Function to control what values are used based on user inputs.  This shows how to return a different value based on the user input provided.

I hope this helps.

Kevin.

pwl Former NetApp Employee

variable / expression syntax?

thanks kevin - this helps.  the info about editing functions is VERY handy:  what's the language used?

as it turns out, one of the questions that prompted this post was because i didn't have enough parentheses to scope the arguments.

i had this:

     volPrefix  =     'odi_' + toLower($SecurityZone) + ( $Size >= 500 ) ? '_unshared_' : '_shared_'

when i should have had this:

     volPrefix  =     'odi_' + toLower($SecurityZone) + (( $Size >= 500 ) ? '_unshared_' : '_shared_')

how about the question of assigning labels to the user input options ?

variable / expression syntax?

Hi Peter,

The language used for the functions is MVEL.  You should just do a web search for MVEL, but a quick link for MVEL information would be here: http://mvel.codehaus.org/.

I'm not quite sure I understand what you're referring to in regards to assigning lables to user input options.  The user inputs are variables and they get set to a particular value.  Based on that value we can 'massage' them in certain ways in order to leverage them effectively in the workflows.  The functions help here too by being able to translate the input provided...and convert that to some other value that can be used within the workflow.

I'll contact you offline to figure out what your asking.  Otherwise the short answer would be "No", for the question of "can we assign lables to user input variables?"

I'll be in touch,

Kevin

pwl Former NetApp Employee

variable / expression syntax?

thanks for the info the the language - that will help.  i've already been able to put together a couple of my own functions based on your advice.

since we're separated by the tyranny of timezones   & for reference for others, i'll try to expand on what i mean about labels.

let's say i set up a set of inputs like this:

See that i've set Security Zone to a enumerated set of strings: ipn,sec, con,  and so on

This means i get a user input dialog that looks like this:

What i would like is to able to make what appears in the input dialog a list like:

   Internal Network

   Secure

   Controlled

   Restricted

   Management

but have the underlying values still remain "ipn","sec","con", etc

This would be equivalent to the HTML <SELECT> and <OPTION> tags, in this form:

<SELECT name="SecurityZone">

   <OPTION VALUE="ipn">Internal Network</OPTION>

   <OPTION VALUE="sec">Secure</OPTION>

   <OPTION VALUE="con">Controlled</OPTION>

</SELECT>

This is really only relevant because i am supplying an enumerated list of fixed values (rather than expecting free input)

If there is no in-built way to do this within the workflow preferences then i'll just create a function.  in general, i'm trying to do what i can at the workflow level, before heading into the more sophisticated levels of customisation.

variable / expression syntax?

Hi Peter,

I think I understand the issue and it is doable.

There are 2 methods to achieve it and the methods depending on the number of values:

1) Simple onaric test

2) Function

Let's say I have the following user input:

$Security_Zone => string:Controlled,Secured

I can create a simple Find chart that has just one return node, in which I define a new variable:

sec_zone => $Security_Zone == "Controlled" ? "sec" : "con"

That would make the transition to what you require pretty easily (BTW, I think we did that together back then

for translation of resource pools (HiCap,Fast...))

Now, if $Security_Zone had 3+ values, this method might lose its potency, and you can go with a function.

You will still define sec_zone in a seperate find chart with just return node:

sec_zone => setSecurityZone($Security_Zone)

Then go and define the following function:

def setSecurityZone(sec_zone)

{

    if (sec_zone == "Controlled")

        { return "con"; }

    else if (sec_zone == "Secured")

        { return "sec"; }

    else

        { return "abcd"; }

}

Obviously you can include more "if" statements as you wish.

I hope that answers the question.

Yaron

pwl Former NetApp Employee

variable / expression syntax?

Thanks Yaron

I couldn't remember if we had put that logic in the define within the findpath or in the user input pane.