Creating, Registering and Calling Custom Actions

Actions are actually Custom messages defined for an entity. Following action is created for lead entity having input and out parameters.

Custom Action Plugin C# code, using input parameter and output parameters.

public class CustomQualify : IPlugin
    public void Execute(IServiceProvider serviceProvider)
       IPluginExecutionContext context = (IPluginExecutionContext
       IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)
       IOrganizationService service=    
            string leadId = string.Empty;
            bool CreateContact = false;
            bool CreateAccount = false;
            bool CreateOpportunity = false; 

            if (context.PrimaryEntityId != null && context.PrimaryEntityId != Guid.Empty)    
                leadId = context.PrimaryEntityId.ToString();

            if (context.InputParameters.Contains("CreateContact") && 
                                      context.InputParameters["CreateContact"] != null)      
                CreateContact = (bool)context.InputParameters["CreateContact"];

            if (context.InputParameters.Contains("CreateAccount") && 
                                        context.InputParameters["CreateAccount"] != null)   
                CreateAccount = (bool)context.InputParameters["CreateAccount"];

            if (context.InputParameters.Contains("CreateOpportunity") && 
                                    context.InputParameters["CreateOpportunity"] != null)   
                CreateOpportunity = (bool)context.InputParameters["CreateOpportunity"];

            if (leadId.Equals(string.Empty)) return;

            QualifyLeadRequest req = new QualifyLeadRequest();
            req.LeadId = new EntityReference("lead"new Guid(leadId));
            req.Status = new OptionSetValue(3);
            req.CreateContact = CreateContact;
            req.CreateAccount = CreateAccount;
            req.CreateOpportunity = CreateOpportunity;
            QualifyLeadResponse res = (QualifyLeadResponse)service.Execute(req); 

            context.OutputParameters["success"] = "Done Successfully";
        catch (Exception ex)
            throw ex;

Register the action plugin, and add step by selecting messge as "msd_CustomQualify" and "lead" as Primary entity.

Calling an action associated with specific entity from web API 

var leadId =, 37);
var ServiceURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.0/";
var ActionName = "msd_CustomQualify";
var parameter = {
    CreateContact: true,
    CreateAccount: false,
    CreateOpportunity: false

var request = new XMLHttpRequest();"POST", ServiceURL + "/leads(" + leadId + ")/Microsoft.Dynamics.CRM." + ActionName, false);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
request.setRequestHeader("OData-MaxVersion", "4.0");
request.setRequestHeader("OData-Version", "4.0");

request.onreadystatechange = function () {
    if (this.readyState == 4) {
        request.onreadystatechange = null;
        if (this.status == 200 || this.status == 204) {
            var data = JSON.parse(this.responseText);
            if (data != null) {
        } else {
            var error = JSON.parse(this.response).error;
            if (error != null)


Also we can created global actions that are not dependent on specific entity, for making an action global we will select entity name as None (global) as shown below.

Calling Global action using web API

var leadId =, 37);
var ServiceURL = Xrm.Page.context.getClientUrl() + "/api/data/v8.0/";
var ActionName = "msd_CustomQualify";
var parameter = {
    leadId: leadId,
    CreateContact: true,
    CreateAccount: false,
    CreateOpportunity: false

var request = new XMLHttpRequest();"POST", ServiceURL + ActionName, false);
request.setRequestHeader("Content-Type""application/json; charset=utf-8");

request.onreadystatechange = function () {
    if (this.readyState == 4) {
        request.onreadystatechange = null;
        if (this.status == 200 || this.status == 204) {
            var data = JSON.parse(this.responseText);
            if (data != null) {
        } else {
            var error = JSON.parse(this.response).error;
            if (error != null)

Adxstudio Portal Website deployment from Dev to Prod

Let’s suppose we need to deploy our adxstudio "Community Portal" wbsite from Dev environment to our production environment.

You should have already installed Adxstudio Studio portal on the Production CRM org with "Community Poral" Website from Website Gallery, and hosted the source code. In short you should have Configured the "Community Portal" website in the Production enviroenment.

Let we have been done lot of changes in Dev CRM org by adding “Web Pages”, “Web forms”, “Content Snippets”, “Page Templates” etc. And let also we have changes in our Dev Website source code. Now we want deploy all these updates/changes for “Community Portal” website from Dev to Prod we need following steps/things:
  1. Copy website from Dev CRM org to Prod CRM org, here we need to migrate the website record with all the related entities records used for website building e.g. “Web Pages”, “Web forms”, “Content Snippets”, “Page Templates” etc.
    For this migration we have to use the WebsiteCopy.exe utility found in the utility folder in the extracted Adxstudio files “C:\Program Files (x86)\Adxstudio\XrmPortals\7.0.0021\Utilities”.
    Exporting Adxstudio Portal website to a backup XML file
    Importing Adxstudio Portal website from a backup XML file
  2. If we have changes in our source code for the Dev website then also we need to move source code from Dev website hosting folder to Prod website hosting folder.
    Copy and paste the source code from the hosting folder of Dev to hosting folder of Prod website, Only we will not copy  settings.xml App_Data/settings.xml, this contains the CRM connection information.

Importing Adxstudio Portal website from a backup XML file

This post shows a step by step process to import a backup XML file of an Adxstudio website to a dynamics CRM org using Website Copy utility's wizard. The process of exporting the backup XML file is in my previous post Exporting Adxstudio Portal Website to a backup XML file

The unitltiy WebsiteCopy.exe utitlity found in the extracted adxstduio files "C:\Program Files (x86)\Adxstudio\XrmPortals\7.0.0021\Utilities"

Double click WebsiteCopy.exe

Click Next

Select XML file as our source is XML file that we have exported here in our previous post, click Next
Select backup XML file, Click Next

Select Microsoft Dynamics CRM server
Select your discovery URL for CRM online - If you case is CRM On-Premises enter the org URL. Click Go.

Enter user name and password, click Next.

select CRM Org, click connect
Specify Destination website name, make sure that no website should be there with the same name you are specifiying here. e.g If there is exist a website with same name "Community portal" then you should rename the website in CRM Org, and after you can delete the existing one as you have imported new and updated copy of the "Commuity Portal" website
Click Next

Click Create website.

Importing website is in progress...
By clicking Save button a Windows Command Script is created that contians all the wizard steps. Next time you can just run that CMD file for completing all the steps.