Skip to content

Tag: Javascript

KeyBox – A Dataverse solution to govern credentials

Posted in Power Platform, and Dynamics 365

Most of the time, I create solutions based on customer requirements. Sometimes, I create solutions to learn something new and “KeyBox” was my last personal project to learn some new skills.

KeyBox – The features

It is a solution to store and govern credentials (stand alone or in regard to a customer) in Dataverse. You can store usernames & passwords or client IDs & client secrets. It reminds you when the “valid until” or “remind me on” date is reached. Additionally, a note can be placed at the MFA switch and a URL.

KeyBox Record

Additionally, you can create new passwords, based on the rules of the organization.

KeyBox Config

I’ve learned in my KeyBox project:

Get your KeyBox!

Sounds like I try to sell you something, but I don’t. I put it on GitHub under MIT licence. Means you can use and modify it in any way you want.

KeyBox

Retrieve EnvironmentVariableValue in JavaScript

Posted in Power Platform, and Dynamics 365

In my private project (Key Box), I stored a JSON configuration in an Environment Variable. To retrieve its value, I had could use two queries. The first query to retrieve the GUID of the Environment Variable Definition and the second query to retrieve the Environment Variable Value. But there is a better way: the RetrieveEnvironmentVariableValue WebApi function.

Below is the async function I wrapped around it to make it easy reusable.

Retrieve EnvironmentVariableValue JavaScript

async function getEnvironmentVariableValue (schemaName) {
  return Xrm.WebApi.online
    .execute({
      DefinitionSchemaName: schemaName,
      getMetadata: function () {
        return {
          boundParameter: null,
          parameterTypes: { 
            DefinitionSchemaName: { 
              typeName: "Edm.String", 
              structuralProperty: 1, 
            } ,
          },
          operationType: 1,
          operationName: "RetrieveEnvironmentVariableValue",
        };
      },
    })
    .then(function success(response) {
      if (response.ok) {
        return response.json();
      }
    })
    .then(function (responseBody) {
      return responseBody["Value"];
    })
    .catch(function (error) {
      console.error(error.message);
    });
}

“Command Checker” bookmarklet

Posted in Dynamics 365, and Power Platform

Last week, I found out that Microsoft released a Command Checker for model-driven-app-ribbons – OVER 2 YEARS AGO! I totally missed that.
I especially love that it shows me the result of each single display rule and enable rule.

To enable the Command Checker as a button in the ribbon bar, you need to add the URL parameter “ribbondebug=true” to the current D365 CE URL and reload it. But who wants to remember ugly URL parameters…

javascript: (var _href = window.location.href; if (_href.includes("ribbondebug")){_href.replace("ribbondebug=false", "ribbondebug=true")} else {_href += "&ribbondebug=true"} window.location.href = _href)

Open these bookmarklet anywhere in model-driven-app, and it will reload the window with the activated Command Checker.

“Advanced Find” bookmarklet

Posted in Dynamics 365, and Power Platform

Since February 2022, Power Platform Admins can enable the “Modern advanced find in model driven apps“. After a decade of continuity, it is great to see a fresh, clean look and some new features in a unified user interface.

In case you are a CRM veteran like me and also miss the old advanced search, I have something for you.

javascript: (window.open(Xrm.Utility.getGlobalContext().getCurrentAppUrl() + "&pagetype=advancedfind"))

Open these bookmarklet anywhere in Dataverse, and it will open a new window with the classic advanced find in it.
Don’t forget to get used to the new advanced find.

“Get attribute by attribute ID” bookmarklet

Posted in Dynamics 365

Background information

Currently, I have a problem while applying a solution upgrade for our managed solution. The message in the solution history gives me the name of the attribute that blocks the uninstallation and its ID, but it did not tell me to which entity the attribute belongs.

Get attribute by attribute ID

To identify the right entity for the attribute professionally and not by trail and error, I looked into the “Query table definitions using the Web API” article on Microsoft Docs and build a browser bookmarklet for an easier use.

The “Get attribute by attribute ID” bookmarket

Copy and paste the following code as URL of a bookmark in your browser and execute it on any D365 page.

javascript:function getDet(){var r=JSON.parse(this.responseText);console.info("MetaData for Entity: " + r.LogicalName);console.dir(r);console.info("MetaData for Attribute: " + r.Attributes[0].LogicalName);console.dir(r.Attributes[0])};function getAtt(){var r=JSON.parse(this.responseText).value,etn,atn;for (let i=0; i < r.length; i++) {if (r[i].Attributes.length > 0) {Xrm.Navigation.openAlertDialog({confirmButtonLabel:"Close",text:"Entity: "+r[i].LogicalName+"\nAttribute: "+r[i].Attributes[0].LogicalName+"\n-\nOpen Browser Console for more MetaData Details (F12)",title:"Found Attribute"},{height:250,width:350});var oReq=new XMLHttpRequest();oReq.addEventListener("load", getDet);oReq.open("GET","/api/data/v9.0/EntityDefinitions(LogicalName='"+r[i].LogicalName+"')?$expand=Attributes($filter=MetadataId%20eq%20"+id+")");oReq.send();break;}}}id=prompt("Enter Attribute ID", "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");var oReq=new XMLHttpRequest();oReq.addEventListener("load", getAtt);oReq.open("GET","api/data/v9.0/EntityDefinitions()?$select=LogicalName&$expand=Attributes($select=LogicalName;$filter=MetadataId%20eq%20"+id+")");oReq.send();

You can paste the attribute ID and receive the logical name of the attribute and of its entity. On top, you can open the browser console to inspect the full output of the WebApi for the attribute.