Tuesday 21 July 2020

Monitor for Model-Driven Apps - Power Platform

Hi Everyone,

It's time to say bye-bye to ask the Users to send fiddler traces as we can monitor every thing from our machine and analyze what exactly we need using Monitor.

Monitor provides you all client-side network of the app on which you can start analysis on the same. I think, it is most useful for the Microsoft Support Team and Product Team as they need the traces from the users to understand the issues and they normally guide with the steps that are needed to log the traces using Fiddler. Now, they can say bye-bye to those and just pass on the URL to the join the monitor debug session and trace everything. However, it would be useful for Technical Consultants as well to understand what is going wrong with the Performance, Script Errors, Form Events etc...

Let's see how it works.

Select the Model-driven app and right click on it, you will see an option as Monitor. 
A new tab will open upon clicking on Monitor button with the button as below.
Hit on Play model-driven app and it opens the App asking you to join the monitor session. If you want, you can join or we can copy the URL and give it to the user to open and perform the actions which they would like to do.
Once the Users join the session, navigate and perform actions whatever you want, you will see the complete traffic from the app is captured in the Monitor window.

As of now, the following events are supported.
  • KPI for page loads, command executions, and other major events
  • Network request details
  • Warnings for synchronous XHR’s
  • Custom script errors (e.g. onload, ribbon rule evaluation)
  • Form execution event details (e.g. onload, onchange)
  • Form visibility reasons for controls and related menu items
  • Power BI control failure and performance events

Refer PowerApps blog post for more information.

Hope this helps.

--
Happy 365'ing
Gopinath.

Monday 20 July 2020

Plug-in Trace Logs not generating in Dynamics 365 CE On Premise

Hi Everyone,

I have started working on On Premise after so many years and I have to understand one of the plugin that was not working in some scenarios. I have written good traces to understand the logic and deployed the plugin.

To my surprise, while testing no plugin trace logs were generating. I was little surprised for sometime and after checking the things slowly came to know that the Plugin Assembly was deployed on None mode(Not in sandbox mode).

I have seen community discussion where people were saying the Plugin Trace Logs are not getting generated under None mode. Hope Microsoft will fix it soon.

https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/189346/plugin-trace-log-not-working-on-dynamics-crm-2016-on-premise

For the time being, I have registered the plugin under Sandbox to get the trace.

Hope this helps.

--
Happy 365'ing
Gopinath.

Azure Function URL not working in New Portal

Hi Everyone,

The other day, I was asked by my Test Team to give them an URL to test a Timer Azure Function that triggers on a weekly basis. Unfortunately, we cannot wait for a week to trigger and hence we have changed that to HTTP Trigger Function and given the URL to the Test Team so that they can hit and run on demand.

Immediately got the response from QA Team saying that the URL provided is not working.
Up on investigation, the URL looked like the one in below image with "/api" in the URL but the same URL was populating without "/api" when we browsed the same using Azure Classic Portal.


When we tried the second URL that was without "/api", it was working as expected.
It could be an error on New Azure Portal as the same is working from Azure Classic Portal. Hope it will get fixed in near future.



Hope this helps.

--
Happy Coding
Gopinath.

Assembly must be registered in isolation - Dynamics 365 On Premise

Hi Everyone,

Today I was working on on-premise system after so many years and as per the requirement I need to update the one of the step from Async to Sync and when I tried doing that, was continuously getting error saying "Assembly must be registered in isolation."

Later I found that that Assembly was registered in "None" mode (Not in Sandbox mode) and the User with which I am trying to update the step doesn't have Deployment Administrator Role.

After adding the User to the Deployment Administrator role via Deployment Manager, I was able to update the step.

Hope this helps.

--
Happy 365'ing
Gopinath.

Sunday 19 July 2020

Coalesce in Power apps - Power Platform

Hi Everyone,

As we all know how we Coalesce() function in SQL, it returns the first non-null value in a list.

For example : If we run the below query, will get the results as StatureStack.com

SELECT COALESCE(NULL, NULL, NULL, 'StatureStack.com', NULL, 'mscrmtechie.blogspot.com');

In simple words, it just returns whatever the first non-null value.

In the same way, we can use Coalecse function in Power Apps formulas as well. Today, I have two variables which has been set from different logic and I had to write the formula to get the not null value between two of them. I used below formula to get the not null value between two variables.

Coalesce(variable1, variable2, ...)


Here is more information from Microsoft Docs

Hope this helps.

--
Happy 365'ing
Gopinath.

Call Power Automate or Microsoft Flow from JavaScript - Dynamics 365 CE

Hi Everyone,

We all know how Power Automate or Microsoft Flows are changing the way we design the things in Dynamics 365 CE. Recently, we got a requirement to call Microsoft Flow from a button click on Dynamics 365. Here is the way we did using JavaScript.

Let's create a flow as below.

1) Take the trigger as HTTP Request received

2) Generate Schema accordingly to your input, I just have AccountID as an Input so taken JSON as below to generate schema and declare the method as POST.
{"AccountId": "abc"}

3) I just added one step of Variable as once the flows is triggered from the JavaScript, we can add the steps as per our requirement.

4) Save the flow and get the URL from HTTP Trigger (first step)

5) Here is the JavaScript code for calling flow.
function callFlowFromJavaScript() {
    var flowUrl = "FLOW URL";
    var input = JSON.stringify({
        "AccountId": "475b158c-541c-e511-80d3-3863bb347ba8"
    });
    var req = new XMLHttpRequest();
    req.open("POST", flowUrl, true);
    req.setRequestHeader('Content-Type', 'application/json');
    req.send(input);

}
To Configure Flow URL in a best way, you can read this Post.

Hope this helps.

--
Happy 365'ing
Gopinath.

Friday 17 July 2020

Delete Change History button on Audit History - Dynamics 365 CE

Hi Everyone,

I was going through Audit History of a record to understand one of the bugs in my project. I have never seen Audit History in the recent times and I was little surprised to see a button as Delete Change History on top of the grid.

With the help this button, we can delete Audit history record by selecting a record by record. However, we might not want to give this permission to all the users in the system. And yes, we have a Privilege that we can remove so that users will not see the button.


Delete Audit Record Change History under Core Records  - Miscellaneous Privileges.

Hope this helps.

--
Happy 365'ing
Gopinath.

Canvas App showing loading icon on Dynamics 365 CE forms - Power Platform

Hi Everyone,

Today I was working on simple Canvas App and I have to show it on Model Driven Form on Dynamics 365 CE. I have published the Canvas App, copied the URL and did set to the IFrame on the form. Here is the configuration of the same.

I have saved the Form, Published and navigated to the Account page. To my surprise, it started showing only loading icon.

I was thinking something going at the Canvas App side but when I play, it is working fine. Came to the conclusion that certainly some thing from Dynamics side is blocking the content. And finally, it is Cross-frame Script which is blocking the content. After un-checking "Restrict cross-frame scripting, where supported. " checkbox everything started working.

Hope this helps.

--
Happy 365'ing
Gopinath.

Set Canvas App URL on Dynamics 365 CE - Power Platform

Hi Everyone,

Today I was talking to one my friends on the deployment of Canvas Apps that were configured as an IFrame on Model Driven Forms of Dynamics 365. The problem with this is, every time deployment happens the URL would be overridden and we have to manually open the properties of IFrame to set it to the right one.

We can write JavaScript to retrieve the URL  from some configuration/setting entity but every time, the call would be executed which we don't want. Here comes our friend Session Storage to help use.

We have added the piece of code to set the URL that is retrieved as Session Storage item and using it to setSrc instead of retrieving Settings/Configuration record every time. In fact, this solution all configurations whatever we are retrieving, we can use SessionStorage or LocalStorage based on the scenario which will eventually reduces the calls from client side and hence improves the performance. 

The only you should remember is to use Unique Name for the session variable, I normally use combination of OrganizationID and Configuration name.

Here is the code for your reference. First checking for the value in the Session Storage and if it contains value, taking it from there otherwise retrieve it and set to IFrame src as well as SessionStorage item with unique name to use next time.


function setCanvasAppsURL(executionContext, controlName, ConfigName) {
    var organizationSettings = Xrm.Utility.getGlobalContext().organizationSettings;
    var formContext = executionContext.getFormContext();
    var sessionVariable = organizationSettings.organizationId + ConfigName;
    var sessionVariableValue = sessionStorage.getItem(sessionVariable);
    var url = null;
    if (ConfigName != null && sessionVariableValue == null) {
        ///Get config value from configuration
        var globalContext = Xrm.Utility.getGlobalContext();
        var parameters = {};
        parameters.ConfigName = ConfigName;
        var req = new XMLHttpRequest();
        req.open("POST", globalContext.getClientUrl() + "/api/data/v9.1/SettingsEntity", true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.onreadystatechange = function () {
            if (this.readyState == 4) {
                req.onreadystatechange = null;
                if (this.status == 200 || this.status == 204) {
                    if (JSON.parse(this.response).ConfigKey != null) {
                        url = JSON.parse(this.response).ConfigKey;
                        if (url != null) {
                            if (formContext.getControl(controlName) != null && formContext.getControl(controlName) != undefined) {
                                formContext.getControl(controlName).setSrc(url);
                                sessionStorage.setItem(sessionVariable, url);
                            }
                        }
                    } else {
                        console.log("Error");
                        Xrm.Utility.closeProgressIndicator();
                        var alertStrings = {
                            confirmButtonLabel: "Ok", text: "Error : " + JSON.parse(this.response).error.message
                        };
                        Xrm.Navigation.openAlertDialog(alertStrings);
                    }
                }
            }
        };
        req.send(JSON.stringify(parameters));
    }
    else
    {
        formContext.getControl(controlName).setSrc(sessionVariableValue);
    }

}

Hope this helps.

--
Happy 365'ing
Gopinath

Change screen size of Canvas App - Power Platform

Hi Everyone,

Today I was on embedding a Canvas App on Dynamics 365 CE forms using Model Driven Form Integration and while creating the Canvas App, it has opened in the mobile layout but as per my requirement I need tablet layout.

After some search came to know change the layout from File --> Settings --> Screen size + orientation.

Check this link for more information.

Hope this helps.

--
Happy 365'ing
Gopinath.

Thursday 16 July 2020

Sorry, we didn't find that App - Canvas App on Model Driven Form

Hi Everyone,

Today I did develop a small canvas app and have to show it in a section on Model Driven form (Account form). I have added a IFrame on the Model Driven Form and gave the URL of the Canvas App to IFrame. Published the form in Dynamics 365 CE and refreshed the Account page and clicked on the Tab where I have placed the Canvas App, it displayed as below.

"Sorry, we didn't find that App"

Not sure what went wrong, did check the App, URL and Tenant (thinking, I have created the app in other tenant). Everything was fine but lastly found the issue, I have Saved the app but didn't Publish. After publishing, everything worked fine. It was a silly mistake but took sometime to understand it.

--
Happy 365'ing
Gopinath.

Invalid type. Expected String but got Null or Invalid type, Expecting Object but got Null - Microsoft Flow/Power Automate

Hi Everyone,

Today I was working on flows and all of a sudden flow started failing with the below error at Parse JSON step.

"Invalid type. Expected String but got Null"

However, was able to understand the issue after checking the input that was passed to Parse JSON step. One of the property value is coming as Null.

The fix is easy, we just need modify the Schema of Parse JSON.

instead of  "type": "string" make it as "type": ["string", "null"] to handle null values.

Hope this helps.

--
Happy 365'ing
Gopinath.

Monday 13 July 2020

How to get the count of items in a Collection - Canvas App/Power Apps - Power Platform

Hi Everyone,

Today I was working on CanvasApp and I have to show the count of the items in the  collection on UI. This can be done easily by using the below formula.

CountRows(CollectionName)

I have given Text property of the label as below and here the result is showing the count.



Check this post on how to get and show the Dynamics 365 CE records using flow on Canvas App. 

--
Happy 365'ing
Gopinath

Sunday 12 July 2020

Required properties are missing from object while parsing JSON in Power Automate or Microsoft Flow

Hi Everyone,

Today I am working on a flow and received below error at ParseJSON Step.

"Required properties are missing from object : property names"


This error is coming as we have specified some of the properties as required in the Schema and as they are not given as an input to Parse JSON, the step is failing while validating the data with schema.

To fix this, we have to edit the schema and remove the properties that were mentioned as Required in the schema. 



If you are 100% clear that you might need the values to pass on, I would be prefer to check the data after parsing it and have your own response step to handle it.

Hope this helps.

--
Happy 365'ing
Gopinath

Get the records from Power Automate (List Records) and display them on the Gallery - Power Platform - Dynamics 365, CDS, Power Automate and Canvas App

Hi Everyone,

In this post, let's try to understand the steps that are needed to get the data from Power Automate using Common Data Service List Records Action and show the same on the Canvas App Gallery.

As a first step, let's build Power Automate to get records from Dynamics 365. 

Take a trigger as a PowerApps as we would calling this flow from Canvas App.

Add Common Data Service Current Environment Connector and List Records step by defining the entity and fields you would like to get.

Run the flow to get the results so that you can generate JSON Schema with that. 
Expand List Records step and click on Download link. It will open the JSON results in the browser window.


Select one record from the result and copy, we will use it to generate schema.

Add Parse JSON step in the flow as next step and take values from List Records steps as an Input to the step.

Click on "Generate from Sample" button on Parse JSON step and put the JSON data that was copied by adding "[" as a starting character and "]" as an ending character so that the result would be converted to an Array.

Once the Schema is generated, make sure you remove the column names in the Required property otherwise your flow would fail with error "Required Properties are missing from object" if some values comes as blank in the result. 


Run the flow once to check the output from Parse JSON step.
The flow ran successfully and you would be able to see the output from Parse JSON step.

Edit the flow and add Response Step, set Body of Response to Body of Parse JSON step.


Click on Show advanced options link and copy the schema from Parse JSON step and put it here.
Save the flow.

Let's create a new Canvas App and add go to Action, Power Automate which will show the list of the flows in your environment.

Select the flow that you would want to use and after adding the flow to Canvas App, provide Parameters if you have any otherwise close the command with parenthesis.

As we need to bind the data to Gallery, we need a Collection object. Let's push the result from flow to a collection. To test the things easily, I have added a button and OnSelect of the button given below statements. This will get the result from flow and assign it to the collection.

ClearCollect(DataFromFlowCollection, GetAccountsFromD365CE.Run());

Let's test it once before we add Gallery to the app. Play the app and click on the button. After the execution, go back to edit mode --> View --> Collections, you can preview the data.

We are able to get the data from flow to CanvasApp, let's add Gallery and bind the collection as a Data Source to it.

You can click on Edit link beside Fields and select which fields you would like to display.

Let's play the App and click on Get Data button to show the data on Gallery.

Hope this helps.

--
Happy App Development
Gopinath