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:
isValidRequest ! = null
AssignMessage
It should not be executed. But it is executing. When we tested same comparison in java script policy we are getting the proper response
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
isValidRequest is true
Thanks,
Some suggestions:
- Initialize that value upfront in your JSC - even if to an empty string - it will avoid the dreaded Undefined creeping into your condition statements.
- OR is your friend (“product.id” != “” OR product.id != NULL) will handle some edge cases.
- 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>