Plugin Inputparamerts!!!

Whenever I get a  requirement for a new plugin, the first thing I will be doing is to analyze the information I derive from  IPluginExecutionContext interface and the input parameters. IPluginExecutionContext interface  Contains information that describes the run-time environment that the plug-in is executing in.
Chances to forget these values are high, hence I post these values here for a quick reference and will be helpful for someone who doesn’t have the time to search these details in the SDK 🙂
Following are IpluginExecutinContext Properties.
Name Description
BusinessUnitId Gets the GUID of the business unit that the user making the
request, also known as the calling user, belongs to.(Inherited
from IExecutionContext.)
CorrelationId Gets the GUID for tracking plug-in or custom workflow
activity execution. (Inherited from IExecutionContext.)
Depth Gets the current depth of execution in the call
stack.(Inherited from IExecutionContext.)
InitiatingUserId Gets the GUID of the system user account under which the
current pipeline is executing.(Inherited from IExecutionContext.)
InputParameters Gets the parameters of the request message that triggered
the event that caused the plug-in to execute.(Inherited
from IExecutionContext.)
IsExecutingOffline Gets whether the plug-in is executing from the Microsoft
Dynamics 365 for Microsoft Office Outlook with Offline Access client
while it is offline. (Inherited from IExecutionContext.)
IsInTransaction Gets a value indicating if the plug-in is executing within
the database transaction.(Inherited from IExecutionContext.)
IsOfflinePlayback Gets a value indicating if the plug-in is executing as a
result of the Microsoft Dynamics 365 for Microsoft Office Outlook with
Offline Access client transitioning from offline to online and synchronizing
with the Microsoft Dynamics 365 server.(Inherited
from IExecutionContext.)
IsolationMode Gets a value indicating if the plug-in is executing in the
sandbox.(Inherited from IExecutionContext.)
MessageName Gets the name of the Web service message that is being
processed by the event execution pipeline.(Inherited
from IExecutionContext.)
Mode Gets the mode of plug-in execution.(Inherited
from IExecutionContext.)
OperationCreatedOn Gets the date and time that the related System
Job was created.(Inherited from IExecutionContext.)
OperationId Gets the GUID of the related System Job.(Inherited
from IExecutionContext.)
OrganizationId Gets the GUID of the organization that the entity belongs to
and the plug-in executes under.(Inherited from IExecutionContext.)
OrganizationName Gets the unique name of the organization that the entity
currently being processed belongs to and the plug-in executes
under.(Inherited from IExecutionContext.)
OutputParameters Gets the parameters of the response message after the core
platform operation has completed.(Inherited from IExecutionContext.)
OwningExtension Gets a reference to the
related SdkMessageProcessingingStep or ServiceEndpoint.(Inherited
from IExecutionContext.)
ParentContext Gets the execution context from the parent
pipeline operation.
PostEntityImages Gets the properties of the primary entity after the core
platform operation has been completed.(Inherited
from IExecutionContext.)
PreEntityImages Gets the properties of the primary entity before the core
platform operation has begins.(Inherited from IExecutionContext.)
PrimaryEntityId Gets the GUID of the primary entity for which the pipeline
is processing events.(Inherited from IExecutionContext.)
PrimaryEntityName Gets the name of the primary entity for which the pipeline
is processing events.(Inherited from IExecutionContext.)
RequestId Gets the GUID of the request being processed by the event
execution pipeline.(Inherited from IExecutionContext.)
SecondaryEntityName Gets the name of the secondary entity that has a
relationship with the primary entity.(Inherited from IExecutionContext.)
SharedVariables Gets the custom properties that are shared between
plug-ins.(Inherited from IExecutionContext.)
Stage Gets the stage in the execution pipeline that a
synchronous plug-in is registered for.
UserId Gets the GUID of the system user for whom the plug-in
invokes web service methods on behalf of.(Inherited
from IExecutionContext.)
Following  are input parameter keys for common plugin messages.

Create

create

Update

update

Assign

assign

Delete

delete

I have included only the common messages, as it could run out to be very lengthy if I include parameter details for all the messages. You can use the dubugger to see the keys for other messages.
Hope this helps 🙂

{New Utility} Record Privilege Checker for Dynamics CRM

Record Privilege Checker for Dynamics CRM

Debajit's Dynamic CRM Blog

Recently I had a requirement where our client’s support and maintenance team wanted a feature through which they can view the privileges for a record for all active users in the system. Ok, let me take a moment to explain here.

Suppose the support team wants to run a regular security check and identify what privilege does a specific user have on specific account records. You might be thinking that is that this hard? After all we can go to the user and identify the security roles of the user. And then determine what access privilege does the security role have on the account

Simple isn’t it? Well it is not. And specially with CRM 2016, a user might end up getting a specific privilege on record through any of the following.

  • Security roles
  • Sharing
  • Access teams
  • Owner team association
  • Hierarchical relationship.

It can be really complex depending on how…

View original post 295 more words

WEB API- Part 6 : Create record

Create record using WEB API 

Following code shows how to create an Account record using WEB API and how to set different types of fields

function CreateAccount() {
 
    var serverURL = Xrm.Page.context.getClientUrl();
    var account = {};
    account["name"] = "New Account";
   
   
 //Set LookUp
    account["primarycontactid"] = {
        "firstname": "Sample",
        "lastname": "Contact"
    };// this will create new contact ,if you need to link an existing contact use the following
 //account["primarycontactid@odata.bind"]="/contacts(contactId)"; 
 
    //optionset
    account["companytype"] = 2;
    //two options
    account["donotemail"] = true;
    //number
    account["numberofemployees"] = 30;
 
    var req = new XMLHttpRequest();
    req.open("POST", serverURL + "/api/data/v8.0/accounts", 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 /* complete */ ) {
            req.onreadystatechange = null;
            if (this.status == 204) {
                var NewAccount = this.getResponseHeader("OData-EntityId");
                var NewAccountId = NewAccount.substr(NewAccount.length - 38).substring(1, 37); 
                Xrm.Utility.openEntityForm("account", NewAccountId); //Open newly created account record
            } else {
                var error = JSON.parse(this.response).error;
                alert(error.message);
            }
        }
    };
    req.send(JSON.stringify(account));
}

 

Please note following code for setting an existing lookup value

 account["primarycontactid@odata.bind"]="/contacts(contactId)";

“contacts” is plural name for contact entity .

var NewAccount = this.getResponseHeader(“OData-EntityId”);  will give  you the newly created record…

WEB API- Part 5 : Get lookup text

Get lookup text using WEB API

Following code will fetch the originating lead lookup text and Id from an opportunity .

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/opportunities?$select=_originatingleadid_value&$filter=_originatingleadid_value ne null", 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=\"OData.Community.Display.V1.FormattedValue\"");
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 _originatingleadid_value = results.value[i]["_originatingleadid_value"];// Id
                 var _originatingleadid_value_formatted = results.value[i]["_originatingleadid_value@OData.Community.Display.V1.FormattedValue"];// text value
            }
        }
        else {
            alert(this.statusText);
        }
    }
};
req.send();

WEB API- Part 4 : Get option-set text

Get option-set text and value using Web API

Following code fetches lead source option-set value and text from lead entity.

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/leads?$select=firstname,leadsourcecode&$filter=fullname eq 'Alex%20Eric'", 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=\"OData.Community.Display.V1.FormattedValue\"");
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 firstname = results.value[i]["firstname"];
                 var leadsourcecode = results.value[i]["leadsourcecode"];
                 var leadsourcecode_formatted = results.value[i]["leadsourcecode@OData.Community.Display.V1.FormattedValue"];
            }
        }
        else {
            alert(this.statusText);
        }
    }
};
req.send();

Please note the following code

" var leadsourcecode_formatted = results.value[i]["leadsourcecode@OData.Community.Display.V1.FormattedValue"];"

“fields name@OData.Community.Display.V1.FormattedValue” will give you the text value of the filed.

Note : Don’t forget to add req.setRequestHeader(“Prefer”, “odata.include-annotations=\”OData.Community.Display.V1.FormattedValue\””);
in the request header

WEB API- Part 3 : Retrieve records modified within last few hours

Using Query Functions:  Retrieve records modified within last few hours 

Query Functions  are intended to be used to compose a query. These functions can be used in a manner similar to the standard library functions,

The following example shows how to use the “LastXHours” to return all account entities modified in the past 12 hours.

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() +/api/data/v8.1/accounts?$select=name,accountnumber&$filter=Microsoft.Dynamics.CRM.LastXHours(PropertyName=@p1,PropertyValue=@p2)&@p1='modifiedon'&@p2=12

For complete list of query functions please follow the link Query functions.

 

WEB API- Part 2: Retrieve Single Record Using WEB API

Retrieve Single Record Using WEB API

Following  code shows how to fetch an account record using  Guid

var req = new XMLHttpRequest();

var AcccountID="257bAC5D5240-8B31-E611-80E4-5065F38B4681";
req.open("GET", Xrm.Page.context.getClientUrl() +"/api/data/v8.0/accounts(AcccountID)?$select=name", 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=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var name = result["name"];
}
else {
alert(this.statusText);
}
}
};
req.send();