CRM Blog

Valcore ApS Logo (c) Valcore ApS 2012

Dynamics Dev Tweaks

To share my solutions/tweaks while developing solutions for dynamics 365 problems that i thing might be helpful / interesting for the audience
A software engineer mostly worked on Microsoft technologies for a dacade.
Started developing Dyanmics 365 solutions for almost 2 years ago.

Button(Ribbon) to Call plugin (pass parameters and receive results)

At some point on the roadmap of every Dynamics 365 (CRM) developer's life, one must have wished to press a button to call a Plugin. 
A combination of Custom Actions introduced in CRM 2013 and webapi introduced in CRM 2016 made this wish very easy. Developers have used different techniques to achieve the same goal e.g. creating records of dummy enttities or updating dummy fields of an entity to call plugins.
There is a smarter way to do so using Custom Actions and here is how we can do it:
Our solution consists of 4 main parts:

1. A CRM custom action with input/output parameters (it can be bound(on an entity) or unbound(global) depending on your requirements)
2. A plugin registered on the custom action (this will perform the task and will set the outpur parameter with results)
3. Script under the button: this will use webapi to call custom action sending input parameters if necessary and will receive the results as output paramters
4. Ribbon button to call the javascript function

User presses a button on a form which fires a javascript function. JS function uses webapi to call the Custom Action and passes input parameters e.g. record's guid. Plugin registered on this custom action gets fired as soon the custom action runs. Plugin gets input parameters and perform actions and finally set the output parameters to be returned. JS function gets the results from the output parameters set by plugin after the plugin finishes processing.

Here is a Sample Javascript function which calls custom action "val_CASCA" passing input parameter "InParameter1" and gets results in output parameter "OutParameter1" set by plugin after processing.

function CallCASCE() {
   var Id ='{', '').replace('}', '');
   var serverURL = Xrm.Page.context.getClientUrl();    
   var data = {
       "InParameter1": Id
   var req = new XMLHttpRequest();
   // specify name of the entity, record id and name of the action in the Wen API Url"POST", serverURL + "/api/data/v8.2/val_scas(" + Id + ")/Microsoft.Dynamics.CRM.val_CASCA", false);
   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 == 200) {
               var result = JSON.parse(this.response);
           } else {
               var error = JSON.parse(this.response).error;
   // send the request with the data for the input parameter

Here is the sample Custom Action "val_CASCA" which is bound to custom entity "SCA" have one imput parameter and one output parameter of types string.

Finally the plugin registerd on this custom action.

public void Execute(IServiceProvider serviceProvider)


string results = string.Empty;
if ((context.InputParameters["Target"] is EntityReference)) { results += "InputParamters[Target] is entityreference"; }
try {

Continue reading
2551 Hits

Using CRM Actions to overcome workflow limitation of access to main or related entities

One of the workflow limitations is; it does not support access to its next related entity. One can only access the main entity or the related entities but not next related entity.

we have 3 entities Account, Contact and CustomEntityA.
Account is related to Contact and Contact is related to CustomEntityA. Account is not directly related to CustomEntityA.


If we want to update a field e.g. description on CustomEntityA on update of the description of Account, or if we want to update Account’s description from CustomEntityA’s description, we cannot do it with OOB workflow. We can either write plugin/customWorkflowActivity or there is another option without coding anything which is combination of Action and Workflow.

Bellow is an example of how to access next related entity using custom action and workflow.

  1. Create a crm process of type Action with two input parameters of entityreference type for those entities that are not directly related e.g. Account and CustomEntityA. Include necessary steps as required by business logic. Her is an example of such Action process:

    In the example below our CustomEntityA is AccContactDesc and we will be updating its description from the description of account as soon the account description changes. 
    Here is the screenshot of worflow of type Action


    Properties of update step:

Continue reading
1171 Hits
Vores adresse:
Industrivej 48
4000 Roskilde, Danmark
Telefon: +45 70 22 14 64
E-mail: Denne e-mail adresse bliver beskyttet mod spambots. Du skal have JavaScript aktiveret for at vise den.
CVR nr.: 34472726
Mandag til Torsdag kl. 09.00 - 16.00
Fredag kl. 09.00 - 15.30
Weekend lukket

Kig forbi!

Hos Valcore er du altid velkommen til at kigge forbi til en kop kaffe og en gennemgang af Microsoft Dynamics CRM. Vi brænder for CRM og vi er gode til at skabe en god forståelse for hvordan CRM kan bruges i en virksomhed, hvad enten der er fokus på salg, marketing, service eller noget helt andet!