As you look to enhance your dataset with additional calculations you might want to combine them into a single calculation. This is most commonly done for performance reasons, especially Links calculations in a People to Positions setup are expensive. This is where you can combine calculations in an On Demand expression, which will improve the performance of the dataset as less calculations will be evaluated dynamically and outputs are also hardcoded into the dataset.
This approach leverages the setValue method with which it is possible to hold multiple Gizmo expressions and calculate these at the same time. Instead of having each calculation run at the individual property level, you must first create a property which will hold the combined calculation and will serve as a method to populate all calculations included. This "Calculate" property must be set to evaluate for all nodes On Demand (i.e. when manually triggered).
Within the "Calculate" property the setValue({...}) syntax is required to ensure that this setup is possible:
Your calculations are performed within the setValue({...}) method. In the above example two calculations are evaluated: Vacancy Flag and Job Share Flag. Notice each calculation consists of two parts:
Another example:
node.setValue({ vacancyFlag: node.links.isEmpty ? "Vacancy" : "Filled", jobShareFlag: node.links.count > 1 ? "Job Share" : undefined, employeeName: node.links.isEmpty? "Vacancy" : node.links.to.fullName.join(", "), employeeGender: node.links.isEmpty? "Vacancy" : node.links.to.gender.join(", "), })
Notice how in this example certain elements of the expressions are repeated. This is where you can introduce variables in your calculation to improve efficiency. Think of a variable (the most common version you will see is "const") as a means to evaluate (part of) your expression which can then be called again later without needing to calculate the same thing again.
const linksEmpty = node.links.isEmpty; node.setValue({ vacancyFlag: linksEmpty ? "Vacancy" : "Filled", jobShareFlag: node.links.count > 1 ? "Job Share" : undefined, employeeName: linksEmpty ? "Vacancy" : node.links.to.fullName.join(", "), employeeGender: linksEmpty ? "Vacancy" : node.links.to.gender.join(", "), })
In the above example 'node.links.isEmpty' is calculated once in the variable. The result is then re-used in the subsequent expressions. This is much more efficient compared to having to calculate the expressions three times which happens in the previous example. The below example takes this one step further, calling a variable within another variable:
const links = node.links; const linksEmpty = links.isEmpty; node.setValue({ vacancyFlag: linksEmpty ? "Vacancy" : "Filled", jobShareFlag: links.count > 1 ? "Job Share" : undefined, employeeName: linksEmpty ? "Vacancy" : links.to.fullName.join(", "), employeeGender: linksEmpty ? "Vacancy" : links.to.gender.join(", "), })
Comments
0 comments
Please sign in to leave a comment.