In my Assign message policy I have a JSON for example like this
<Payload contentType="application/json">{a:"A","b":"{example.B}"}</Payload>
if {example.B} is null or undefined,
is there a way not having b in the JSON?
i.e.:
{a:"A"}
Solved! Go to Solution.
I don't think you can implement any programming logic related to policy itself inside a particular policy.But, You can achieve the same using Javascript Policy / Using policy conditions.
For example, Using Javascript,
var payload = {a: "A"}; if (context.getVariable("example.B") != undefined) { payload.b = context.getVariable("example.B"); } context.setVariable("customPayload", JSON.stringify(payload));
Using Policy Conditions, you need two Assign Message Policies,
Policy 1 , If b is not undefined, Execute below policy using policy condition where you check for value of example.B,
<Payload contentType="application/json">{a:"A","b":"{example.B}"}</Payload>
Proxy 2, If b is undefined, Execute below policy using policy condition where you check for value of example.B,
<Payload contentType="application/json">{a:"A"}</Payload>
Hope it helps.
I don't think you can implement any programming logic related to policy itself inside a particular policy.But, You can achieve the same using Javascript Policy / Using policy conditions.
For example, Using Javascript,
var payload = {a: "A"}; if (context.getVariable("example.B") != undefined) { payload.b = context.getVariable("example.B"); } context.setVariable("customPayload", JSON.stringify(payload));
Using Policy Conditions, you need two Assign Message Policies,
Policy 1 , If b is not undefined, Execute below policy using policy condition where you check for value of example.B,
<Payload contentType="application/json">{a:"A","b":"{example.B}"}</Payload>
Proxy 2, If b is undefined, Execute below policy using policy condition where you check for value of example.B,
<Payload contentType="application/json">{a:"A"}</Payload>
Hope it helps.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |