How do I use expressions to compare values of properties (objects)

There needs to be care when using comparison i.e. == and != for instance within an if statement in conjunction with node.property syntax.

For the comparison to work correctly, OrgVue must be able to identify the object type.  In the following example this "identification" will not be effective:

The objective of the code below is to flag where a node has the same business area to their parent.

if(node.businessarea == node.p.businessarea) {
"same"
}
else {
"different"
}

which will only ever evaluate to "different" regardless of the business area under analysis.

The problem here is that both node.businessarea and node.p.businessarea are object references without a declared type, and OrgVue is evaluating if the object being evaluated is the same in both cases - it is not as one is the parent node, one the child node - not evaluating the businessarea property values concerned.

This problem is avoided provided the type is set on the right hand side of the evaluation is set explicit:

node.entrygrade != 5
node.companyname == "Concentra"

i.e. the first expression evaluate node.entrygrade as numeric type and checks if the value is not 5, in the second expression evaluates node.companyname as string type and checks if the value is equal to Concentra.

When comparing object references, the required approach is to add the keyword .value on the right hand side of the expression to ensure the type and value of the object reference is evaluated correctly i.e.

if(node.businessarea == node.p.businessarea.value) {
"same"
}
else {
"different"
}

which will return "same" provided that the type and value of the object references node.businessarea and node.p.businessarea are the identical e.g. Finance

 

 

 

 

 

 

 

Have more questions? Submit a request

Comments