Archive

Archive for the ‘PowerApps’ Category

Dataverse Web API | JScript | EDM.Date conversion issue

September 15, 2021 Leave a comment

While triggering ‘Create’ Action from jScript using the Web API we were getting following Edm.date conversion exception:

An error occurred while validating input parameters: Microsoft.OData.ODataException: Cannot convert the literal ‘2021-09-22T18:30:00’ to the expected type ‘Edm.Date’. —> System.FormatException: String ‘2021-09-22T18:30:00’ was not recognized as a valid Edm.Date.

Reason:

  • In the Create Request payload, there was a Date value which was causing Edm.Date conversion issue.
  • Following is the code snippet used to create a record for the custom table ‘raj_jobhistory’:
var entity = {};
entity.raj_companyname = "Microsoft";
entity.raj_startdate = Date.now();
entity["raj_employer@odata.bind"] = "/raj_employers(8D34D0F4-3F11-EC11-B6E6-000D3A3BA21F)";

Xrm.WebApi.online.createRecord("raj_jobhistory", entity).then(
    function success(result) {
        var newEntityId = result.id;
    },
    function(error) {
        Xrm.Utility.alertDialog(error.message);
    }
);
  • In the above script, ‘raj_startdate’ is ‘Date only‘ field which was being set to ‘Date.now()’.
  • For ‘Date only‘ field, Web API accepts the ‘yyyy-mm-dd‘ format. Since the date format was not being sent as yyyy-mm-dd application throwing the exception.

Fix:

  • Use toISOString() function to change the date value format to yyyy-mm-dd.
  • Following is the modified script.
var entity = {};
entity.raj_companyname = "Microsoft";
// Use toISOString() to change the Date format to yyyy-mm-dd
entity.raj_startdate = Date.now().toISOString().split('T')[0];
entity["raj_employer@odata.bind"] = "/raj_employers(8D34D0F4-3F11-EC11-B6E6-000D3A3BA21F)";

Xrm.WebApi.online.createRecord("raj_jobhistory", entity).then(
    function success(result) {
        var newEntityId = result.id;
    },
    function(error) {
        Xrm.Utility.alertDialog(error.message);
    }
);
Notes:
  • EDM stands for Entity Data Model. OData service uses an abstract data model called  (EDM) to describe the exposed data in the service.
  • Refer this article on the usage of Dataverse Web API.

🙂

Categories: PowerApps

Tip | Model Driven Apps | Client API | setSharedVariable and getSharedVariable

As we know Client-side scripting using JavaScript is one of the ways to apply custom business process logic for displaying data on a form in a model-driven app, In this article lets understand how to pass variables between event handlers (i.e., Different jScript functions registered as event handlers).

Lets understand this by first understanding the Form event pipeline.

Form event pipeline:

  • We can define up to 50 event handlers for each event. Each event handler is executed in the order that it is displayed in the Event Handlers section in the Events tab of the Form Properties dialog box.

setSharedVariable:

  • Sets the value of a variable to be used by a handler after the current handler completes.
  • Syntax : ExecutionContextObj.setSharedVariable(key, value);
    • Ex : ExecutionContextObj.setSharedVariable(“sharedAccountName“, formContext.getAttribute(“name”).getValue());

getSharedVariable:

  • Retrieves a variable set using the setSharedVariable method.
  • Syntax: var sharedVariable = ExecutionContextObj.getSharedVariable(key);
    • Xrm.Navigation.openAlertDialog({ text: ExecutionContextObj.getSharedVariable(“sharedAccountName“) });

🙂

Code Snippet | JScript | Capture BPF Stage Parameters

Below is code snippet to capture the BPF stage parameters up on the ‘Stage’ change using jscript.

function onload(executionContext) {
    var formContext = executionContext.getFormContext();
    // Register event handler on Process Stage Change
    formContext.data.process.addOnStageChange(onStageChange);
}

function onStageChange(executionContext) {
    var formContext = executionContext.getFormContext();
    var stage = formContext.data.process.getSelectedStage();
    // Get Stage Name
    var currStageName = stage.getName();
    // Show Stage Name
    Xrm.Navigation.openAlertDialog({ text: "Current StageName - " + currStageName });

    // Get Stage ID
    var stageID = stage.getID();
    // Get Entity Name
    var stageEntityName = stage.getEntityName();
    // Get Stage Status
    var stageStatus = stage.getStatus();
}
  • Save this script as web resource and register both the ‘onload’ and ‘onStageChane’ functions on form’s onload event.
  • Below is the example of script on Opportunity form.

🙂

Categories: PowerApps Tags: , ,

[Step by Step] Dataverse | Connect Cloud flow with Service Principal (Application User)

By default, Cloud flow Dataverse connectors run under the Owner (i.e., User who created the flow) context. When the flows move to different environment via solutions, connectors run under the user account who imported the Solution.

Making the flows run under interactive user accounts is not recommended as they cause confusion when we check the record’s audit for who updated the record. Its recommended to make the flow run under ‘Application User’, if the calling user can be a fixed account.

In this article lets see how to make the flow run under Application User using Connect the flow using Service Principal option.

High level design:

Following are the steps we gonna go through.

  • App registration in Azure Active Directory (AAD)
  • Create an Application User in Environment.
  • Create a Cloud Flow and connect with Application User.

App registration in Azure Active Directory (AAD)

  • Add a Secret and save the Secret.
  • Copy the Application ID and Tenant ID.
  • Refer this article for the detailed ‘App Registration’ steps.

Create an Application User in Environment

  • Click on ‘New app user’ and select ‘Business Unit’ and ‘Security Role(s)’.
  • Click on ‘Add an app’ and select the App registered in previous section.
  • You should see the ‘Application user’ listed as below.

Create a Cloud Flow and connect with Application User:

  • Connect to Maker portal and create a new Solution.
  • Click on New -> Cloud flow.
  • Click on ‘Connect with Service Principle’.
  • Provide the details captured in Azure Active Directory ‘App Registration’ section and click ‘Create’.
  • Now you should see that in ‘Connection references’ as below.
  • If you go back to the ‘Solution’, you would see a new entry ‘Connection Reference (preview)’ along with the flow.
  • With the ‘Connection Reference (preview)’, we can conveniently move flow to different environment using Solution export and import.
  • Lets proceed and complete the flow, which creates a ‘Contact’ record upon the creation of an ‘Account’.
  • Create an ‘Account’ from the ‘Customer Service Hub’ App.
  • A ‘Contact’ gets created triggered from the flow and Owner would the ‘Application User’.

Notes:
  • You can use ‘Run as’ option and make the ‘Dataverse’ run under one of the highlighted User contexts.

🙂

[Preview Feature] Model Driven Apps | Edit Command Bar

In this article lets explore the ‘Edit Command Bar’ preview feature available in Model Driven Apps designer. But first lets understand the following basics of Command Bar.

  • What are Command Bars?
  • Where do we find them in Model Driven App (i.e., Command bar locations)?

What are Command Bars?

  • Command bars are at the core of every model-driven app and appear in many different locations.
  • The group of commands associated with a specific location make up a command bar.

Command bar locations in Model Driven App:

  • Main grid. This command bar is displayed when using the left-hand navigation of an app to view a full page list of records in this table.
  • Main form. This command bar is displayed on the table’s main forms. This appears at the top of the form and is not the same as the associated view or subgrid view that will appear in different areas of the form.
  • Subgrid view. This command bar is displayed on forms of other tables that render this table’s data within a subgrid.
  • Associated view. This command bar is displayed on the form of a parent table when viewing related data in this table.
  • Quick actions. There isn’t a specialized entry point from the command designer because quick actions are edited from the main grid of the table.

Now that we got the basics, lets explore editing the Command bar.

Using ‘Edit command bar (preview)’:

  • To use ‘Edit command bar (preview)’ feature. Connect to Power Apps portal.
  • Create a new ‘Model-driven app from blank’ and select the ‘Modern app designer (preview)’.
  • Add a Page and link one of your Dataverse Table.
    • I’ve added ‘Student’ table as Page.
  • Now click on ‘…’ of ‘Student’ and click on ‘Edit command bar (preview)’.
  • From the options choose one of the ‘Command Bar’ location you would like to edit.
  • In the next screen, you will get all the available of Commands displayed as below.
    • At this point editing ‘Legacy button is not supported’. Refer the limitations here.
  • I am going to add a new ‘Command’ named ‘Open My Blog’ which opens up an URL.
  • Click on ‘+New command’ and provide details on the right pane.
  • Action property specifies what happens on the ‘Select’ of the ‘Command’. Below are 2 available options.
  • As I need to open URL on the select of my ‘Open My Blog’ command. Under Action’ choose ‘Run formula’ and in the formula bar add ‘Launch()’ Power Fx as below.
  • Click ‘Save and Publish’ and ‘Play’.
  • On your App, you should see the command and on select it redirects to the provided URL.

Refer the docs link for more details.

🙂

Categories: PowerApps Tags: ,

[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.

🙂