Getting incorrect response when compare both null and undefined in proxy and targets endpoints

Not applicable

I am seeing different error when I compare both null and undefined. I have set a variable in context.

context.setVariable("isValidRequest",valid);// Here we are setting value as undefined.

EX:

<step>

<Condition>isValidRequest ! = null</Condition>

<Name>AssignMessage</Name>

</step>

It should not be executed. But it is executing. When we tested same comparison in java script policy we are getting the proper response

0 2 1,657
2 REPLIES 2

using null or undefined from scripts can be tricky, for eg, the values are serialized when its assigned to a variable, for eg, the value for valid could be something like 'org.mozilla.javascript.Undefined@260dac34'

Can you use a boolean instead? for eg,initialize valid with boolean

var valid= false;

..

context.setVariable("isValidaRequest",valid)

---

In your policy condition, you can use

<Condition>isValidRequest is true</Condition>

Thanks,

Not applicable

Some suggestions:

  1. Initialize that value upfront in your JSC - even if to an empty string - it will avoid the dreaded Undefined creeping into your condition statements.
  2. OR is your friend ("product.id" != "" OR product.id != NULL) will handle some edge cases.
  3. Whenever possible, test for the affirmative cases - helpful when you have a known domain of acceptable values.

Snippet in a JSC that does some decoding of variables and makes sure to assign a good value:

var product.id = context.getVariable("product.id");
if (!product.id) product.id = "";
else product.id = decodeURIComponent(product.id);
context.setVariable("product.id", product.id);

Subsequent flow steps implement a condition as follows:

<Step>
    <Name>buildRequestByID</Name>
    <Condition>(product.id != "")</Condition>
</Step>
<Step>
    <Name>buildRequestAll</Name>
    <Condition>(product.id == "")</Condition>
</Step>