how to use ternary operator in AssignMessage policy for variable?

Not applicable

I want to use ternary operator to change value of variable. I don't want to use Javascript policy. Is there any other way to do the same?

Solved Solved
1 4 723
1 ACCEPTED SOLUTION

For sure you can use a very small JavaScript to do ternary logic for an assignment.

In addition, We have an enhancement in the pipeline that would allow a "template" to be used for AssignVariable. The ticket number is APIRT-1180, and @vijay@apigee.com is looking after it. I'm not sure if this would satisfy your desires or not.

Basically it will allow you to do this:

<AssignVariable> 
  <Name>name-of-variable-to-be-set-here</Name>
  <Template>something{variable-here}-something-else</Template> 
</AssignVariable> 

As part of the message template, there is a feature that allows you to specify a value for a variable reference, if the variable is false. For example,

<AssignVariable> 
  <Name>myVariable</Name>
  <Template>{undefined_variable:na}</Template> 
</AssignVariable> 

...will set myVariable to "na" . Does that satisfy? This feature isn't available yet, but I hope that it will be reviewed and released soon.

If this does not satisfy, I'd like to understand what you mean by "ternary". Can you explain the need?

View solution in original post

4 REPLIES 4

Ternary operator cannot be used inside assign message policy, you will have to use a javascript policy

Thanks for your reply @snehal chakraborty 🙂

For sure you can use a very small JavaScript to do ternary logic for an assignment.

In addition, We have an enhancement in the pipeline that would allow a "template" to be used for AssignVariable. The ticket number is APIRT-1180, and @vijay@apigee.com is looking after it. I'm not sure if this would satisfy your desires or not.

Basically it will allow you to do this:

<AssignVariable> 
  <Name>name-of-variable-to-be-set-here</Name>
  <Template>something{variable-here}-something-else</Template> 
</AssignVariable> 

As part of the message template, there is a feature that allows you to specify a value for a variable reference, if the variable is false. For example,

<AssignVariable> 
  <Name>myVariable</Name>
  <Template>{undefined_variable:na}</Template> 
</AssignVariable> 

...will set myVariable to "na" . Does that satisfy? This feature isn't available yet, but I hope that it will be reviewed and released soon.

If this does not satisfy, I'd like to understand what you mean by "ternary". Can you explain the need?

Thanks @Dino. This will resolve my need. Waiting for release of this feature.
Thanks Again 🙂