Recently we looked at the With() function1 and some basics around Delegation2, including a quick sample of combining the two.
Today, let’s look a little closer at a couple of more examples of using the With() function. First, we’ll look at how to use With() to overcome delegation warnings. Then we’ll show an example of how With() can increase the speed and responsiveness of your app by minimizing calls to your data source.
Example 1 - Delegation Warnings
Back in the introduction to With we used a nested With statement as our syntax example. Let’s step back and walk through how we got to this final solution.
We start with the base formula, in this example we are trying to get the Townhome Type value for a particular project by matching the ClientJobID to a variable and then filtering to find the value based on the Type Id field. Note – this example uses a LookUp within a First(Filter()) statement but a nested LookUp – LookUp(LookUp()) – would get the same result. Here we can see the delegation warning on the Filter statement where Id = TownhomeTypeId.
In the second attempt, we use a single With statement to handle the LookUp but you can see this doesn’t resolve the delegation warning on the Filter statement.
So finally we try nested With statements for both the LookUp and the Filter functions and – Success! – no delegation warnings.
Example 2 - Minimizing Calls to the Data Source
This final example leverages the With function to improve our app’s performance by minimizing repeated duplicate calls to the data source.
Note, that if we had not used a With function here, we would have had to perform the same LookUp call 6-7 times to build our address variable as shown. By using the With function we can call the data source once, receive the record as a response, and then build our concatenated address from the result. One call does it all, as they say!
Hopefully these couple of examples have helped illustrate the benefits of the With() function.