Archive

Archive for the ‘PowerApps’ Category

[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: ,

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.

🙂

Canvas App | Dataverse | Distribute columns to multiple forms and Patch

January 18, 2021 Leave a comment

When working with large tables in Canvas App’s Phone layout Forms, it would be counterintuitive to place all the fields in a single form. In below screen, user has to scroll a lot to fill all the details.

In this article, lets see how we can simplify above screen by distributing fields in multiple forms and finally use the Patch function to save the information in to Dataverse from all the forms.

I am taking the OOB ‘Contact’ table in this scenario and distributing fields in to 3 screens (i.e., Basic Details, Contact Details and Additional Details). Lets get started.

  • Create a new Canvas App from Maker portal.
  • From the ‘Data’ tab, Select ‘Entities -> Current environment -> Contacts’ table and add to the App.
  • Add 3 screens (Basic Details, Contact Details and Additional Details) to distribute fields.
  • In the Basic Details screen (i.e., scrBasicDetails), add a new Form (i.e.,formBasicInfo) and add following fields from ‘Contact’ Datasource.
  • Add a Button, to navigate to next screen (i.e., scrContactDetails). Add following formula on ‘OnSelect’ of button.
  • Similarly, In the Contact Details screen (i.e., scrContactDetails) add a new Form (i.e.,formContactDetails) and add following fields from ‘Contact’ Datasource.
  • Add a Button, to navigate to next screen (i.e., scrAddlDetails) by triggering ‘Navigate’ function on ‘OnSelect’ of button.
  • In the last ‘Additional Details’ (i.e., scrAddlDetails) screen, add a new Form (i.e.,formAddlDetails) and add ‘Attachments’ field to capture and store documents to Dataverse.
  • Since this is our final screen, Add a Button to Submit the data to Contact table in Dataverse using following ‘Patch’ function.
  • Post submit refresh the forms using NewForm() function.
  • Display a banner message using ‘Notify’ function.
  • Finally Navigate back to first screen (i.e., scrBasicDetails) using Navigate() function.
  • Combined formula is as below.
// Patch : Use Patch with the Defaults function to create records.
// form.Updates : Gets the data from the fields presented on the from.
Patch(
    Contacts,
    Defaults(Contacts),
    formBasicInfo.Updates,
    formContactDetails.Updates,
    formAddlDetails.Updates
);
// NewForm : Sets the form mode to Insert so that you can submit a new Contact.
NewForm(formBasicInfo);
NewForm(formContactDetails);
NewForm(formAddlDetails);
// Notify : Display notification
Notify(
    "Contact submitted successfully",
    NotificationType.Success
);
// Navigate : Navigates to first screen
Navigate(scrBasicDetails);
  • Run the App, provide details and navigate to next screen and upload images and finally click ‘Submit’ to save data to Dataverse.
Combined screenshot of 3 forms
  • Now go to Dataverse using Model Driven App and open the Contact -> Audit History, to prove only one transaction triggered with our Patch function.

🙂

Categories: PowerApps Tags: , , ,