How to do Null check condition before setting up a header in assign message policy ?

Not applicable

I am setting up a new header from the "Assign Message" policy using a variable.

I want to have some conditional flow (to do Null check) before setting up the header.

For Eg:

If (accesstoken.user-foo != null) {

<Set>

<Headers>

<Header name="FEContext">{accesstoken.user-FEContext}</Header>

</Headers>

</Set>

}

How can I do this ?

Solved Solved
1 2 2,591
1 ACCEPTED SOLUTION

@nishah,

You can't set headers or variables under a specific condition within AssignMessage policy. But you can achieve this in one of the following ways:

  1. Execute AssignMessage Policy only if a specific condition is met (using Condition Flow Variable). In the AssignMessage policy, you can set the header in the usual way. OR
  2. Set the header in a Javascript code using the if block

Regards,

Amar

View solution in original post

2 REPLIES 2

@nishah,

You can't set headers or variables under a specific condition within AssignMessage policy. But you can achieve this in one of the following ways:

  1. Execute AssignMessage Policy only if a specific condition is met (using Condition Flow Variable). In the AssignMessage policy, you can set the header in the usual way. OR
  2. Set the header in a Javascript code using the if block

Regards,

Amar

To elaborate what Amar told, you should have a your code looking like this:

1. Your proxy flow should look like this:

<Step>
	<Name>JsCall.CheckNullValueofFoo</Name>
</Step>
<Step>
	<Condition>(isNull = "false")</Condition>
	<Name>Assign.Headers</Name>
</Step>

2. JsCall.CheckNullValueofFoo Policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript timeLimit="0" enabled="true" continueOnError="false" async="false" name="JsCall.CheckNullValueofFoo">
	<FaultRules/>
	<Properties/>
	<ResourceURL>jsc://CheckNullValueofFoo.js</ResourceURL>
</Javascript>

3. JsCall.CheckNullValueofFoo.js

var isNull = true;
var user-foo = "";
var user-foo = context.getVariable("accesstoken.user-foo);

if (user-foo)
	context.setVariable("isNull",false);

4. Assign.Headers

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage enabled="true" continueOnError="true" async="false" name="Assign.Headers">
	<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
	<AssignTo createNew="false" type="request" />
	
	<Set>
	    <Headers>
	        <Header name="FEContext">{accesstoken.user-FEContext}</Header>
	    </Headers>
	</Set>
</AssignMessage>

Hope this helps