Month: February 2019

Search For Privilege Name Using Privilege Id

Quick post on how to search for privilege/permission name using privilege Id. You often in dynamics receive an error like below during your plugins or Web Api requests.:

“user is missing privilege ba09ec92-12c4-4312-ba16-5715c2cbd6da”

looking at the error, its difficult to tell what is the permission missing and on what entity.

Use this approach

All privileges are stored in an entity called privilege : Read more here.
you cannot see this entity in dynamics CRM front-end as its not available however you can easily query this entity using Web Api.

  1. Get web api url of your organization by going to Settings > Customizations > Developer Resources > Web API instance url:

    i.e. https://organizationname.api.crm8.dynamics.com/api/data/v9.1/

  2. Append this url with “privileges?$select=name” and put it in your browser: https://organization.api.crm8.dynamics.com/api/data/v9.1/privileges?$select=name

    1

  3. hit Ctrl+F and search using id:

    1.png

  4. Now we know the id refers to “PrvReadContact”. Go to the security role and assign appropriate read access on contact entity.

    hope this helps!

Plugin on Retrieve Multiple in CRM.

Filtering records using javascript in subgrid or a view is unsupported and doesnt work hence here is how you can/should filter subgrid records using a plugin.

Nishant Rana's Weblog

Recently we had a requirement to filter sub grid on one of the forms. We thought of using Plugin on Retrieve Multiple for this.

Here we were showing Opportunity Sub Grid on Account form.

So we created a view for Opportunity that will be used as Sub Grid. Used it as Related Record Sub Grid so that we can have the GUID of the Account record being passed to the plugin.

The problem we faced à Sorting and Paging stopped working for the Sub Grid.

http://crmtipoftheday.com/2015/10/05/limitations-of-retrieve-plugins/v

Hope it helps..

View original post

Prevent Data loss/Duplicates Using Concurrency Behavior In Dynamics CRM

This blog is just a reference to very important article on dealing with a problem when two or more update or delete operations on the same piece of data happen at the same time. This situation could potentially result in data loss.

Explanation : Reduce potential data loss using optimistic concurrencyReduce potential data loss using optimistic concurrency.

Sample Code : Use optimistic concurrency with update and delete operations

Get User’s Teams Using WebApi JavaScript In Dynamics 365

If you need to get current/logged in or of any other user’s all teams. You have to look for the N:N relationship schema name and use that association in WebApi request:

1

So below is the code you can use to achieve this requirement. I have just retrieving the name of the teams associated and putting an alert on Onload of a form.

I have generated the code using Rest Builder Tool . And added the filter ($filter=systemuserid eq  IdOfTheuser) manually.

function GetUserTeams()
{
    var userSettings = Xrm.Utility.getGlobalContext().userSettings; // userSettings is an object with user information.
    var current_User_Id = userSettings.userId; // The user's unique id
    var newid = current_User_Id.slice(1, -1);	
    var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/teams?$select=name&$expand=teammembership_association($filter=systemuserid eq "+newid+")", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var results = JSON.parse(this.response);
            for (var i = 0; i < results.value.length; i++) {
                var name = results.value[i]["name"];
                             
                alert(name);
            }
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();
}

I am calling the function on Onload event of lead record. My user has two teams associated to it:

1


2


Important – Make sure you format the code fully before you use it. i.e use the latest method in the script i.e not using Xrm.Page but rather the formContext for v9.

I hope this helps! Cheers!