[Step by Step] Postman tool with Microsoft Dataverse Web API

July 21, 2021 1 comment

Couple of years ago, I’ve blogged Postman tool using Dynamics 365 online. In this article, lets go through the steps to connect Postman tool with Dataverse Web API.

While most of the steps are unchanged, there is a simplified way now to connect to Dataverse Web API with out the need of registering App in Azure AD. Lets get started.

Pre-requisites:

  • Power Apps Environment (Subscribe to 30 days trial, if you have not one).
  • Postman Desktop App. (Download here)
    • Note: These steps will not work with Postman web version.

Get Dataverse Environment URL:

  • Connect to Power Apps portal.
  • Select the ‘Environment’ you wish to connect from Postman tool.
  • Click on ‘Settings -> Advanced Settings’
  • Copy the URL up to the ‘dynamics.com/’ from the new window as shown below.
  • Add ‘.api’ before ‘.crm.dynamics.com’ to the URL.
  • Copy and Save this URL, which would be used in next steps.

Set up Postman Environment:

We would need ‘Workspace’ and ‘Environment’ to get started with Postman.

  • Open the Postman tool and create a new ‘Workspace’ if not having already.
  • Click on create a new ‘Environment’.
  • In the ‘Add Environment’ screen, we need to add Variables related to ‘Dataverse’ which helps Postman to connect Dataverse Web API.
  • Following 6 variables need to be configured.
Variable reference diagram
  • Lets add the first Variable “url“. In the ‘INITIAL VALUE’ paste the Dataverse environment url copied in previous section.
  • Repeat the step for next 5 variables and looks as below. Click ‘Add’ to save the Postman ‘Environment’.

Authorize Postman to Dataverse Environment:

Now that we have Postman Environment ready with required variables. Lets authorize and connect the Postman to Dataverse Web API. For that we need to complete ‘Authorization‘ and generate a new ‘Access Token’.

  • Select to the new Postman ‘Environment’ created in previous section.
  • Create a new GET ‘Request’ and select {{webapiurl}} variable as url.
  • Click on ‘Authorization’ tab and select ‘TYPE’ as ‘OAuth 2.0’ and click on ‘Get New Access Token’.
  • Provide details as below in the ‘Get New Access Token’ screen and click ‘Request Token’.
  • In the next screen, provide the Office 365 credentials.
  • Post successful authentication, a new ‘Access Token’ gets generated as below. Click ‘Use Token’.
  • ‘Access Token’ expires every 1 hour and you would get “401 Unauthorized’ exception upon expiry.
  • Click on ‘Get New Access Token’ if the Token expires to get a new Access Token. From 2nd time, Token generates instantly without any further sign-in.

Connect Postman to Dataverse Web API and query:

As we completed ‘Authorization’ and got the ‘Access Token’, we are good to query Dataverse API.

  • Create a new GET ‘Request’ and select {{webapiurl}} variable as url.
  • In the ‘Authorization’ tab, select the ‘Access Token’ generated and click ‘Send’.
  • You should get the Response as below with 200 Status code.
  • Below is the sample to fetch Top 3 Account records.

🙂

Canvas Apps | Optimization | Quick way to find and clean unused variables

Many a times, in Canvas Apps we would have declared variables but no longer used them. In a complex App with substantial screens, its tedious to identify and clean up the unused variables.

In this article, lets learn how to identify unused variables and clean up. If you are unversed with ‘Variables’, refer this article.

On a high level, Set() is used to define Global variable and UpdateContext() or Navigate() are used to define Context variable (i.e., Scope limited to a screen).

To understand unused variables and clean better, I’ve built a simple Canvas App using below steps.

  • Create a new Canvas App from Power Apps portal.
  • On App ‘OnStart’ event, declared 4 Global variables using Set().
  • Add a new Screen with 3 buttons. As buttons Text, used the one of the global variables(i.e.,btnLabel1) declared in App ‘OnStart’. Repeated the same for other 2 buttons.
  • To understand Context variables, on “btn1’s” OnSelect declared 2 context variables using UpdateContext().
  • Now that we got both Global and Context variables, lets understand about variables in-depth.
  • Go to File -> Variables, you will find 2 tabs ‘Global’ and ‘Screen1’ (this is for Screen1 Context variables).
  • Now click on one of the Variables, and you will find 3 tabs:
    • Definitions : Statement where this variable was declared. In our case its App ‘OnStart’.
    • Uses : Where this Variable used.
    • Indirect uses :  Any control indirectly refers the variable. Lets see this in detail in next step.

  • Click on ‘Uses‘, you will find where ‘btnLabel3’ directly referred (i.e., Text of button 3).
  • To understand ‘Indirect uses‘, lets add a new Label and set the Text as “This is indirect label of a Button : ” & btn3.Text“.
  • In the above statement, ‘Button 3’ text was ‘Directly’ set to ‘btnLabel3’ variable, here new Label’s text was set to ‘Button 3’ text, which indirectly referring ‘btnLabel3’ variable.
  • Now, click on ‘Indirect uses‘ of “btnLabel3” variable and you would see the new Label’s text statement.
  • Coming back to the crux of this article, to identify a Unused variable, click on Variable and go to ‘Uses‘ tab. If its blank, you can navigate to the declaration statement from ‘Uses‘ and remove the statement.

🙂

Categories: CRM, PowerApps Tags: ,

Power Platform | 2021 Wave 1 | Features

With 2021 Wave 1, lots of new features introduced across the Power Platform (i.e., Power BI, Power Apps, Power Automate, and Power Virtual Agents) and the two add-ins (i.e., AI Builder and Power Apps portals).

2021 Release Wave 1 Plan, contain the features releasing from April 2021 through September 2021. Features list can be downloaded from here.

In this article, lets see the few key features/enhancements included in this release.

Dependent assemblies for plug-ins:

  • Plug-in developers have long used an unsupported capability provided by the ILMerge utility to combine a plug-in assembly plus any needed dependent assemblies together into a single .NET assembly.
  • The dependent assemblies capability provides a supported way for developers to include additional dependent assemblies along with the plug-in assembly when registering a plug-in.

Plug-in telemetry with Application Insights integration:

  • Customers who have associated their Environment with their Application Insights resource can view telemetry for log events written from their plug-in code.
  • ILogger is a standard interface for writing log events.
  • ILogger interface enables writing log events for a set of log levels, such as Trace, Debug, Information, Warning, Error.
  • The developer doesn’t need to configure or include Application Insights SDK assemblies because everything is already set up.

Advanced lookup:

Multi-table lookups:

  • If you are familiar with data type Customer, which connects to both Account and Contact, its Multi-table lookup.
  • Multi-table lookup type columns allow a user to employ a specific table that has multiple one-to-many (1:M) relationships to other tables in the environment. A single lookup type column can refer to multiple other tables.
  • This new feature gives users the power to define any other multi-table lookups they may need.

Removing business units from security role assignments:

  • Business units can be removed from a user’s security role assignment for ease of use and to simplify the business unit security model.
  • By decoupling a user’s business unit from their security role’s business unit, they can be assigned security roles from different business units. This allows the user to access the respective business units without the need to create and join the owner team.

Virtual Connector Provider for tabular connectors:

  • As we know, Virtual tables (Formerly known as ‘Virtual Entity’) enable the integration of external enterprise data with Microsoft Dataverse without the need for data duplication.
  • With the introduction of the Virtual Connector Provider for Dataverse, data residing outside of Microsoft Dataverse can be easily represented and used as Microsoft Dataverse virtual tables using supported tabular connectors (for example, SQL Server, OneDrive, Excel, SharePoint, and more).

Model-driven app adds in-app notifications:

  • In-app notifications in model-driven apps are shown to users as a notification or in the notification center.
  • Notifications are directed to a specific user and can be sent through external systems, Power Automate, or from within the system.

Power Apps component framework for canvas app:

  • Public preview of Power Apps component framework allows developers and makers to add datasets and test their custom components in canvas apps, taking advantage of the growing list of supported framework APIs.
  • Pro-dev extensibility on a low-code platform opens up possibilities enabling the best of both worlds.

Link a Microsoft Dataverse environment to Azure Synapse Analytics workspace and bring Dynamics 365 data to Azure:

  • With this feature, you can use Export to Data Lake to link a Microsoft Dataverse environment to Azure Synapse Analytics workspace and bring Dynamics 365 data that’s stored in Microsoft Dataverse to Azure.
  •  It enables a seamless integration with Azure Synapse, which provides the necessary compute to analyze data in the Data Lake using features, such as SQL on-demand.
  • These features provide a familiar T-SQL syntax to query data in the Data Lake without the need to copy or load data into a specialized store.

Auditing enhancements:

The following changes have been made to Auditing:

  • Audit data is stored in log storage.
  • Administrators can set a retention period for audit data.
  • Expired data will automatically be removed from the system per the retention period.
  • Joining entities from the database storage and the log storage will no longer be possible.

Bypass Custom Business Logic:

  • Refer my previous article on this feature.

🙂

Categories: PowerApps Tags: ,

Dataverse | Bypass Custom Business Logic

There are times when you want to be able to perform data operations without having custom business logic applied. Especially during complex data migration scenarios, we would not want our custom business logic (i.e., Sync Plug-ins/Real time Workflows) to be triggered.

The manual option to disable custom logic is,

  • We have to locate and disable the custom plug-ins. But this means that the logic will be disabled for all users while those plug-ins are disabled. It also means that you have to take care to only disable the right plug-ins and remember to re-enable them when you are done.

Now using BypassCustomPluginExecution option we can disable custom business logic programmatically.

About BypassCustomPluginExecution:

When you send requests that bypass custom business logic, all synchronous plug-ins and real-time workflows are disabled except:

  • Plug-ins which are part of the core Microsoft Dataverse system or part of a solution where Microsoft is the publisher.
  • Workflows included in a solution where Microsoft is the publisher.

There are two requirements:

  • You must send the API requests using the BypassCustomPluginExecution option.
  • The user sending the requests must have the prvBypassCustomPlugins privilege. By default, only System administrator’s have this privilege
    • The prvBypassCustomPlugins is not available to be assigned in the UI at this time. We can add a privilege to a security role using the API.

Using BypassCustomPluginExecution:

  • Web API:
    • Pass MSCRM.BypassCustomPluginExecution : true as a header in the request.
POST https://yourorg.api.crm.dynamics.com/api/data/v9.1/accounts HTTP/1.1
MSCRM.BypassCustomPluginExecution: true
Authorization: Bearer [REDACTED]
Content-Type: application/json
Accept: */*

{
  "name":"Test Account"
}
  • Organization Service:
    • Set BypassPluginExecution to true at the service, it will remain set for all requests sent using the service until it is set to false.
var svc = new CrmServiceClient(conn);

svc.BypassPluginExecution = true;

var account = new Entity("account")
{
    Attributes = {
        { "name", "Test Account" }
    }
};

svc.Create(account);
  • At Request class level:
    • BypassPluginExecution parameter, which is Optional, must be applied to each request individually.
    • You cannot use this with the 7 other IOrganizationService Methods, such as Create, Update, Delete.
    • You can use this method for data operations you initiate in your plug-ins.
var svc = new CrmServiceClient(conn);

var account = new Entity("account")
{
    Attributes = {
        { "name", "Test Account" }
    }
};

var createRequest = new CreateRequest
{
    Target = account
};

createRequest.Parameters.Add("BypassCustomPluginExecution", true);

svc.Execute(createRequest);

Adding the prvBypassCustomPlugins privilege to another role:

  • Because the prvBypassCustomPlugins is not available in the UI to set for different security roles, if you need to grant this privilege to another security role you must use the API.
  • The prvBypassCustomPlugins privilege has the id 148a9eaf-d0c4-4196-9852-c3a38e35f6a1 in every organization.
  • Code Snippet:
var roleId = new Guid(<id of role>);

service.Associate(
    "role",
    roleId,
    new Relationship("roleprivileges_association"),
    new EntityReferenceCollection {
        {
            new EntityReference("privilege", new Guid("148a9eaf-d0c4-4196-9852-c3a38e35f6a1"))
        }
    }
);

Refer Docs article for more details.

🙂

Power Apps | Sharing | Restrict ‘Everyone in Environment’ option using PowerShell

In Power Apps, by default Users with ‘Environment Maker’ role can create and share the Apps. One of the sharing option is ‘Everyone in Instance’, which grants access to all Users in the Azure tenant.

In one of our requirements, we had to restrict the ‘Share with everyone’ option for the ‘Environment Makers’ and limit to ‘Global Admins’. Lets see how to achieve this in this article.

Scenario:

In my Power Apps account, I got 2 Users.

  • Rajeev – Global Administrator.
  • Jayansh – Environment Maker.

User Jayansh, created an App named ‘Simple App’ and wants to share. By default ‘Everyone in Environment‘ option is enabled.

Lets restrict this option using the following PowerShell commands.

PowerShell script:

  • Open the PowerShell console in ‘Administrator’ mode.
  • Execute Add-PowerAppsAccount command to connect to the Power Apps tenant.
  • Execute following command, to check the current state of ‘Share with everyone’ (i.e., Everyone in Environment) option. It returned ‘False’ in my case, which means ‘Share with everyone’ option is available .
    • $settings = Get-TenantSettings
    • $settings.powerPlatform.powerApps.disableShareWithEveryone
  • Lets turn off the ‘Share with everyone’ option using following command.
    • $settings.powerPlatform.powerApps.disableShareWithEveryone=$true
    • Set-TenantSettings $settings

Try Sharing the App as ‘Environment Maker’

  • Connect to Power Apps portal as User ‘Jayansh’ who is ‘Environment Maker’.
  • Select the App and click ‘Share’. Select the ‘Everyone in MS‘ (MS is my environment name) and click ‘Share’.
  • An exception message will be thrown as below.

Try Sharing the App as ‘Global Administrator’

  • Connect to Power Apps portal as User ‘Rajeev’ who is ‘Global Administrator’.
  • Select the App and share using ‘Everyone in MS‘ option.
  • And the App gets shared successfully.

🙂

Categories: PowerApps Tags: ,

Power Apps Developer Plan

In May 2021, Power Apps Community Plan has been extended to meet the needs of developers and rebranded as the Power Apps Developer Plan.

What is a Developer Plan:

  • Power Apps Developer Plan gives us a free development environment to build and test with Power Apps, Power Automate, and Microsoft Dataverse.
  • This Developer Plan is meant for development and test use only. A paid plan is required to deploy or run solutions in a production environment for production use.

Developer plan included following changes compared to the Community plan:

  • Ability to share apps with team members for development and testing purposes.
  • Increased capability allocations.
  • Ability to create more environments to support ALM (Application Lifecycle Management) scenarios (coming soon).

Existing Power Apps Community Plan users will also get all these updates.

Developer Plan Limitations:

  • The following capacity limits apply for the individual environments.
CapacityLimits
Flow runs/month750
Database size2 GB
  • You can’t add any other user as an Environment admin or a Maker, or to the database roles from the admin center.

Sign up:

  • Signing up to Developer Plan can be done using work or school account. Signing up with a personal account is not currently supported.
  • Click here to sign up.

🙂

Canvas App | Display and Download large data sets of Images from Azure Blob Container with no delegation issues

In one of my previous articles, I detailed the steps to embed a Canvas app with upload image to Azure Blob feature.

In this article lets see, how to work with large data sets and achieve following:

  • Displaying blob images in Gallery.
  • Ability to Download the image.
Pre-requisites:
  • Azure Storage Account and Container. Get free Azure subscription here
  • Dynamics 365 account. Get 30 days trail here

Set up Azure Storage Account and Container

  • Connect to your Azure portal.
  • Create a new Storage Account and capture the Storage Account ‘Name’ and ‘Access Key’.
    • I’ve named Storage Account name as ‘expmar’
  • Create a new Container and copy the Name.
    • I named my Container as ’employee’.
  • Upload few images, which will be used to display in Canvas App.

Steps to create Canvas App and Connect to Azure Blob

Create Azure Blob Storage Connection:
  • Connect to Power Apps Portal using your Dynamics 365 account.
  • To connect to Azure Storage Account from Canvas App, we need a new ‘Azure Blob Storage’ Connection.
  • Click on ‘Data -> Connections -> Azure Blob Storage’ and provide Azure Storage Account ‘Name’ and ‘Access Key’ captured in previous section and click ‘Create’.
  • Up on successful creation, you should see the ‘Azure Blob Storage’ under ‘Connections’.
Steps to Create Canvas App and display blob images
  • Create a new Canvas App.
  • Add the ‘Azure Blob Storage’ connection created in previous step to the Canvas App from ‘Data -> Add a connection’.
  • As we established connection to Azure Storage Account, next, connect to ‘Container’ (i.e., Employee) and read the images to a List.
  • Use following formula on App’s ‘On Start’ event.
  • This formula, reads the images from ’employee’ Container and store the images in ’employeePhotos’ Collection.
  • Now we have the images in ’employeePhotos’ Collection, add a Gallery control and bind to ’employeePhotos’ Collection.
  • To display images, In the Gallery, add an ‘Image’ control and in the ‘Image’ property add following formula.
  • To display image name, add a ‘Label’ control and set Text as ‘ThisItem.DisplayName’.
  • To check whether images are rendering click on ‘App -> Run OnStart’ and you should see the images upload to Azure Blob Container in the Gallery.

Steps to Build Download feature
  • To download an image from Azure Container, we would need following 2 values:
    • URL : Azure Storage Account URL.
      • URL format would be “https://{Storage Account Name}.blob.core.windows.net
      • In my case, its “https://expmar.blob.core.windows.net”
    • SasToken (Shared access signature Token):
      • Generate the ‘Shared access signature’ as below from Azure portal.
  • Set ‘URL’ to ‘bloburl’ and ‘Token’ to ‘sastoken’ variables ‘OnStart’ of the App.
  • Complete ‘OnStart’ formula looks as below.
  • Add a ‘Download’ icon to the Gallery.
  • On ‘OnSelect’, use ‘Download(bloburl & ThisItem.Path & sastoken)’ formula.

Test the App
  • Run the App and you should see Images and ‘Download’ icon as below.
  • Click on ‘Download’ icon and image should get downloaded.

🙂

Categories: PowerApps Tags: , ,

Canvas App Import Failure | CanvasAppEnvironmentMismatch error

February 9, 2021 Leave a comment

We configured a new Dynamics Instance copied from another Instance using ‘Customizations and schema only’ option.

While importing a solution with a Canvas App, the solution import failed with CanvasAppEnvironmentMismatch error

CanvasApp import: FAILURE: Code: CanvasAppEnvironmentMismatch Message: The specified app ‘xxx-xx-xxxx-xx’ belongs to the environment ‘xxx-xx-xxxx-xx’ and not ‘xxx-xx-xxxx-xx’ which is the environment associated to instance ‘xxx-xx-xxxx-xx’

Its a strange because, the Instance is a copied one and there were no Canvas Apps exist, when checked in the PowerApps Portal -> Apps tab.

Reason:

  • Even though the PowerApps portal not showing up any Apps, when queried the ‘Canvasapps’ Data Verse entity using oData URL, there were Canvas App records pointing to a different Instance (i.e., The Source Instance which the current instance copied from).
    • Copy the name of the App from json collection. We would need it in next steps.
  • Solution import failed because of the matching Canvas App entry pointing to a different Instance in ‘Canvasapps’ entity.

Fix:

  • Write a C# console and delete the entry in ‘Canvasapps’ entity.
  • Following is the sample code.
 var queryCanvasApps = new QueryExpression("canvasapp")
                {
                    ColumnSet = new ColumnSet(true)
                };

                var filter = new FilterExpression(LogicalOperator.And);
                var cond1 = new ConditionExpression("name", ConditionOperator.Equal, "{App_Name copied in above section}");

                filter.Conditions.Add(cond1);
                queryCanvasApps.Criteria = filter;

                var apps = CrmService.RetrieveMultiple(queryCanvasApps);

                foreach (var app in apps.Entities)
                {
                    //Delete the App entry
                    CrmService.Delete("canvasapp", app.Id);
                }
  • Post deletion, reimport the solution and it should work.

🙂

‘Callback Registration Expander’ System Jobs stuck at ‘Waiting For Resources’

January 30, 2021 1 comment

We set up a new Dynamics Instance by copying from another Instance using ‘Copy environment’ option from Power Platform Admin Center.

We opted ‘Copy over’ as ‘Customization and schema only’, as we don’t need the data to be copied over to the Target instance.

On the Target instance we’ve started the Data Migration activity and noticed frequent connection timeouts. When checked the ‘System Jobs’, there were many “Callback Registration Expander” Jobs stuck at “Waiting For Resources” state.

Reason:

  • To understand “Callback Registration Expander” jobs , lets first understand Callbackregistration entity.
  • ‘Callback Registration’ entity stores the configuration of Processes and Cloud flows (i.e., Power automate flows).
  • So, if you create a new Flow on the instance, a new entry goes in to ‘Callback Registration’ entity.
  • Coming back to our issue, when we configured the new Instance using Copy option, “Callback Registration Expander” jobs from the source instance copied to new instance.
  • Since the “Callback Registration Expander” jobs looking for records from Source instance, which are unavailable in Target, jobs stuck at “Waiting For Resources” state.

Fix:

  • Its a product issue.
  • To fix the issue, We had to delete the ‘Callback Registration’ records from new instance.
  • Create a flow or write a C# console to delete the ‘Callback Registration’ records.
  • This deletion step, deletes the entries carried over from Source instance.
  • Now, disable and enable flows in new Instance which create new entries in ‘Callback Registration’ records.

🙂

[Step by Step] Debug Model Driven and Canvas Apps using ‘Monitor’ tool

January 26, 2021 Leave a comment

Monitor tool overview

Using Monitor tool,

  • Makers of canvas apps can view events while building a new app or to monitor published apps.
  • Makers of model-driven apps can monitor page navigation, command executions, form-related issues, and other major actions.

Using Monitor with Model Driven App

Lets see step by step to use Monitor with Model Driven App.

  • Connect to Power Apps Portal.
  • Select the Model Driven App from either from ‘Apps’ tab or from ‘Solutions’ and select the ‘Monitor’ option from Command bar.
  • A new Monitor session opens up as below in a browser tab.
  • Click on ‘Play model-driven app’ to start the diagnosis.
  • After the app is opened from Monitor, you’ll see a Join monitor debug session? dialog box. Select Join.
  • A notification shows up to denote monitor is in progress.
  • While you navigate through the Model driven app, events begin to flow to the Monitor session screen.
  • You can also ‘Invite’ other to monitor the session.
Events monitored

Following are few events we can track in Monitor tool.

  • FullLoad : Signifies the complete load of a page navigation, such as an edit form load. This event waits for certain network requests to complete and all rendering to finish, so the form can be ready before FullLoad completes.
  • Network : Reveal details about each request made from the app.
  • Page navigation, command executions, form saves, and other major actions will send key performance indicators and network events to Monitor.
  • Script errors: Monitor receives events from the app with more details about the script errors, so you can debug more quickly, and easily.

Using Monitor with Canvas App

Using Monitor, we can trace events as they occur in a canvas app during the build, or we can use Monitor to debug the published version of a canvas app.

Monitor Canvas app during the build
  • Open the Canvas app using ‘Edit’ option.
  • From the ‘Advanced Tools’, select Monitor -> Open monitor.
  • A new browser tab opens Monitor screen and connects it to your existing Power Apps Studio session. A notification appears as “Studio Session”, which denotes its Canvas app during build.
  • Run the ‘Canvas’ app and you would see the events logged as below.
Monitor Published Canvas app
  • Select the App and select ‘Monitor’ Or, you can select More Commands (), and then select Monitor.
  • A new browser tab opens Monitor screen. Click on ‘Play published app’.
  • This action opens the published app in a new browser tab and connects it to your current Monitor session.
  • You would notice a banner and record kind of icon at the top.
  • To view the source expressions in Monitor for the published app, you need to turn on the setting to publish the expressions with the app. 

Notes:

  • You can run a model-driven app and add “&monitor=true” to the end of the URL in the browser. Then, select Monitor on the command bar to start a monitoring session in a new tab.

🙂