Dataverse – melgaard.nu https://melgaard.nu Blog about Dynamics 365, Power Platform, and everything in between Thu, 04 Jul 2024 14:01:39 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.7 https://melgaard.nu/wp-content/uploads/2024/06/cropped-cropped-Designer-4-1-32x32.jpeg Dataverse – melgaard.nu https://melgaard.nu 32 32 Dataverse Custom Telemetry Not Exporting to Application Insights https://melgaard.nu/custom-telemetry-not-exporting/ Sun, 23 Jun 2024 18:12:12 +0000 https://melgaard.nu/?p=178

I am working intensively with Application Insights (I want to see and act on errors before my users do!), and when I write plug-ins, I like to export custom telemetry to Dataverse. You can read more about it in the Microsoft Learn article.
Also see this excellent blog post

One interesting issue I had with one of my newly created environments was that it refused to export custom telemetry. It exported everything else. I tried to create new exports, pointing at other Application Insights instances, nothing worked!

It turns out that the telemetry key in this environment was not set correctly for some odd reason. So, the solution was to set it manually by patching it on the Dataverse instances organization record. 
It’s relatively straightforward.

Find the instrumentation key for the Application Insights instance you want to export to

Find the GUID of the Organization from the Power Platform Admin Center

Update the column “telemeetryinstrumentationkey” for the “organization” record of the Dataverse environment, to the instrumentation key of the Application Insights instance. And for good luck sake, set the “orginsightsenabled” to true.
Notice that the “telemeetryinstrumentationkey” will appear as null if you lookup the record.


You can see how to do it easily from the browser here:

You should now see your custom telemetry being exported to Application Insights.

]]>
Patching Dataverse Records Directly from the Browser Without Plugins https://melgaard.nu/patching-browser/ Sun, 23 Jun 2024 17:27:07 +0000 https://melgaard.nu/?p=161

Quite recently, I needed to do some data manipulation in a pinch in one of my heavily restricted Dataverse environments. The environment was only accessible from specific IPs, and the only tool I had available at the time was my browser—no executables allowed!
I could not find an example of how to do this directly from a browser, so it made a good topic for a blog post.
It is possible in the browser! This also means it’s possible to use the same authentication as the browser, with no need to re-authenticate.

Method 1: Patching using the javascript console

I got this one from an old Microsoft support case.

This approach is universally applicable, regardless of the browser you’re using. It’s particularly useful in scenarios where you don’t have access to the built-in tools, such as the network console in Edge.

Your browser might be different, but here is the procedure in Edge.
Open the developer console by hitting Ctrl – Shift – I (Or opening settings – More tools – Developer tools)

Click on the Console button. You might want to clear the console by clicking the clear button left to “top”

Copy this Javascript (Remember to change the values!), paste it into the console, and hit enter.

var queryPath = *Your dataverse instance*/api/data/v9.2/*table you want to patch*(*record GUID*);
var param = {};
param["Column to patch"] = "Column value";
 
var req = new XMLHttpRequest();
 
req.open("PATCH", queryPath, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
 
req.onreadystatechange = function () {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            alert(this.status);
        }
        else {
            alert(this.status);
        }
    }
};
req.send(JSON.stringify(param));

It should look something like this if all goes well. I have detached the DEV console, it makes I a bit easier to work with.

If you get a “204” alert, that means that it went well and that you patched the record.

Method 2: Using the network console in Edge

This one is a slight twist on the first one. Instead, it uses the network console in Edge’s developer console to create the patch record.
Start by opening the Network console but clicking the Network console icon.

Click on the “Create Request” button. 
Change the method from “GET” to “POST”
Open “Body,” change the type to “Raw text” and enter the column and value as JSON.

{
    "column 1":"value",
    "Column 2":0.01
}


It should look something like this, and as the first example, if it returns 204, it went through.

I hope it makes sense, otherwise, do let me know (-:

]]>