Posts

Efficient way to check Logged In user's security role

Image
As a CRM developer, we all have developed functionality to check logged-in user's security roles. We used to get GUID of security role and then we have to fire a query to the server-side to get the role names. Thankfully Microsoft has slipped in an update to get the role names. Xrm.Utility.getGlobalContext().userSettings  has been updated with a new function called roles ,   which returns a collection of lookup objects containing the GUID and display name of each of the security roles assigned to the user and any security roles assigned to the team that the user is associated with. Let's take look at this with a scenario: I have to perform some functionality if the current user has  Sales Manager or Marketing Manager  role assigned to him. And here is the result: currentUserRoles object contains all the roles assigned to the logged In user and isValidUserRoles contains the result after filtering the currentUserRoles object with required roles. Click here for...

The optimized and efficient way to execute multiple API requests in one call

Image
As a developer, we have to optimize the code for better performance. Sometimes we have to make multiple API calls for different kinds of functional logic or validation on a single event, which leads to performance issues. Microsoft already has a feature called Batch Operations , but it involves a lot of code, and also the response we received is not in a JSON format. To overcome this we can use another API calling mechanism called fetch()  to execute multiple APIs. This method provides an easy, logical way to fetch resources asynchronously across the network. Let's take a look at this with an example. Here we have created an array of URLs called urls  which consist of two different API calls, the first API call to get owner details and the second API call will give the team details if a user is part of a particular team. Executing all APIs included in urls array. The responses for API will be received in the same order as an Array element. Here are the responses received:...