Access EMML variable default value?

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi guys,

is it possible to access the default value of the variable defined within a mashup script?

I have an idea but it would only work if I can access the default value at runtime.

Cheers, Innes

4
Your rating: None Average: 4 (1 vote)
smithac
smithac's picture
User offline. Last seen 1 year 14 weeks ago. Offline
Joined: 10/28/2009
Points: 2

Hi Innes,

Default value of a variable can be accessed within a mashup script at runtime.

This can be done as shown below:

<variable name="total" type="number" default="0" />

<assign fromexpr="$total + 10" outputvariable="total" />

Please let me know if this addresses your concern.

Thanks,

Smitha

 

 

smitchell
smitchell's picture
User offline. Last seen 17 hours 16 min ago. Offline
Joined: 08/29/2008
Points: 34

By access do you simply mean use it somewhere in the mashup logic? Update it? Or access it even after the variable has been updated? Just not sure what you are asking.

Smitha's reply illustrates the basic usage. When you define a default value for an input parameter or a variable, that value is used when the variable is referenced up until the variable is updated. Once the variable has been updated, however, the default value is no longer available.

 

 

Sara, technical writer/jackbe

 

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Hi Smitha, Sara,

Sorry ... probably didn't explain it quite right. What I meant was, can you access the default value of the defined variable programmatically during runtime, say from a Groovy script. I'm just curious as to whether I can grab the default value set in the input or variable definition before anything is done to update the variable.

Ok .. so you probably are thinking why would I want to do that.  It goes back to an earlier post asking whether the default value gets picked up when you don't specify an input variable value. I was wondering if I could create a function/macro that is called something like setDefaultValueIfNull(variablename[, variablename]) that determines if the value of a specified variable is null then grab its default and sets that as its current value.

Just a thought ...

See 3) in this post www.jackbe.com/enterprise-mashup/forum/multiple-input-parameters-invoke-statement

Cheers, Innes

smithac
smithac's picture
User offline. Last seen 1 year 14 weeks ago. Offline
Joined: 10/28/2009
Points: 2

Hi Innes,

For your question:

-- if the value of a specified variable is null then grab its default and sets that as its current value.

For example say a service requires 5 input params and instead of specifying the paramName if i give 

<invoke service="EmpDetails" operation="getData" inputvariables="'Smitha',,,,," outputvariable="result"/>

Now for this service there are 4 null values. How would a service  recognise and pick the appropriate inputvariable for each null value? It will throw error message saying 'Missing required field'...../ .....

However, If I specify the paramName It will pick the default value.

<variables>

<variable name="appid" type="string" default="ydndemo"/>

<variable name="zip" type="string" default="94040"/>

</variables>

<invoke service="YahooZipCodeSearchREST" operation="getData" inputvariables="appid,zip" outputvariable="result" />

You can also override the default value by doing

<invoke service="YahooZipCodeSearchREST" operation="getData" inputvariables="appid,'95053'" outputvariable="result" />

Thanks,

Smitha

nzblue_fish
nzblue_fish's picture
User offline. Last seen 2 weeks 4 days ago. Offline
Joined: 09/30/2009
Points: 1165

Thanks Smitha,

Giving the inputvariable name to pick up the default would do the trick. I was looking for a way to be able to set a variable to a default when you missed it out in the sequence of a multi-param call, for example:

<variable name="appid" type="string" default="ydndemo"/>

<variable name="city" type="string" default="Hamilton" />

<variable name="zip" type="string" default="94040"/>

</variables>

<invoke service="YahooZipCodeSearchREST" operation="getData" inputvariables="'myDemo',,'123456'" outputvariable="result" />

So that "city" would then have defaulted to "Hamilton" as it was left out in the call.

I think in my original testing I found that missing out a parameter (such as the second one above) didn't generate an error, rather it set the value to null.

Cheers, Innes

smithac
smithac's picture
User offline. Last seen 1 year 14 weeks ago. Offline
Joined: 10/28/2009
Points: 2

Hi Innes,

You have to mention the inputvariable name while invoking a service/operation in a multi-param call. This will help the service to pick up the default value, if provided.

Hope this helps you,

Smitha