Fetching multiple columns of a record
Optimizing an app is a very crucial aspect of making production ready apps. A very common use case is to fetch multiple columns of a record. To review how to optimize fetching of multiple columns of a record, we will use the example of a user record. As illustrated in my previous post, you can use the Lookup function with and without the dot operator to fetch a column.
Set(
gblUserMainPhone,
LookUp(
Users,
'Primary Email' = User().Email
).'Main Phone'
);
Set(
gblUserMobilePhone,
LookUp(
Users,
'Primary Email' = User().Email
).'Mobile Phone'
);
Set(
gblUserUserName,
LookUp(
Users,
'Primary Email' = User().Email
).'User Name'
);
Set(
gblUserMobilePhone,
LookUp(
Users,
'Primary Email' = User().Email
).'Mobile Phone'
);
Optimized fetching of multiple columns of a record
As you can see from the code above, there are 4 separate data calls to fetch 4 different column values of the same user record. The more optimized approach is to fetch the entire user record once, store it in a variable and then use the variable to fetch values of different columns.
Set(
gblUser,
LookUp(
Users,
'Primary Email' = User().Email
)
);
Set(
gblUserMainPhone,
gblUser.'Main Phone'
);
Set(
gblUserMobilePhone,
gblUser.'Mobile Phone'
);
Set(
gblUserUserName,
gblUser.'User Name'
);
Set(
gblUserMobilePhone,
gblUser.'Mobile Phone'
);
Here is an image of the monitor tool showing the difference in times taken for these 2 approaches:
2 thoughts on “How to optimize fetching multiple columns of a record”