How to assign different values to a variable using single AssignMessage Policy

Hi,

I have requirement where in we need to set different value to a variable based on header parameter.

if condition X="a", then set Var1 to Value1

if condition X="b", then set Var1 to Value2

if condition X="c", then set Var1 to Value3

else set Var1 to Value4

One option is to use conditional flow and use different assign message policy to set the variable value. But this will result in lot of Assign message policies.

Other alternative is to use Java scripts. But many community forums say Java script has performance issue and recommend to use policies.

So, Is there a way to use Single AssignMessage policy and assign different value to variable based on certain condition.

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-SetVariableValue1">
    <DisplayName>AM-SetVariableValue1</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>var1</Name>
        <Value>Value1</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>



<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-SetVariableValue2">
    <DisplayName>AM-SetVariableValue2</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>var1</Name>
        <Value>Value2</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
1 1 2,479
1 REPLY 1

HI @soujanyaedunuri

For your use case, you can very well use JS policy. Don't think there are any performance issue with JS as such. For your particular case, you can very well use JS policy.