This blog entry started as a reply to a question on the Visual Builder technical forum about fetching master and detail tables. While working out a solution, I found a couple of techniques and tips that would be useful to document for future users.
Let's assume you have a master/detail relationship between departments and the employees working in them. You want to be able to show on a single page a list of all the departments and when you select one of them show the full information about that department and the employees working in it, you also want to minimize the number of REST call you perform to fetch that data.
In the video below I show the solution while highlighting some tips and techniques including:
- Enabling accessors (0:35) - this allows us to fetch related objects in a single query. You do this by configuring the relationship between your business objects and checking the box for the relationship you need.
- Defining a type that will control the data that will be retrieved (2:35) - We define a type that contains data from both the master and detail records. When we assign this type as the type returned (response type field) from the call to the REST end point (5:02), we tells Visual Builder to leverage the accessor we defined. Note that when calling the REST service from other locations you can use the expand URL parameter for the REST call to fetch the details in addition to the master record (read more about the expand option here).
- Assigning an array into an ADP while clearing the ADP (5:35) - a little feature of our variable assignment dialog that you might have missed (I know I did until David K told me about it) - where you can specify to empty an array before you add new values into it in a declarative way.
Here we go: