Thursday, 19 January 2017

New things on Dynamics 365



Prepare client customization has the bug fixed for Service Interaction. Check out this link from  MSDN

Customer Data type in Dynamics 365

Dynamics 365 has introduced a new data type for custom fields. its called Customer. When new field is created with this data type, the new field will act as parent customer id field in account/contact. Meaning there will be a look up created on the entity that can look up to both contact and account. Sweetness!!

Thursday, 25 September 2014

Jquery Ajax call example

function GetXrmElement() {
function CreateDebitTransaction() {                
                var Params = {
                    Leader : “Col. Hannibal Smith”,
                    Driver: “Cor. BA Baracus”,
                    Logistics: “Sgt Pedelton”,
                    pilot: “Lef Mardoc”
                };
                $.ajax({
                    type: "GET",
                    url: // ,
                    data: JSON.stringify(Params),                
                    data: Params,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {                        
                 // success method call back
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert("Error Occured while executing the requese.");
                        return;
                    }
                });
            }




above is an asynchronous, non cross browser supported method. synchronous calls does not support jsonp. we can use async attribute but it has some limitations.

according to JQuery API documentation,


async (default: true)
Type: Boolean
By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().

to make it look like sync call i normally put the continuation of the code in the success or error method. not the best work around but work around none the less.

for cross domain purposes some websites say using headers like below resolves the issue. although i have not tested it.

function GetXrmElement() {
headers: { 'Access-Control-Allow-Origin': '*' }
/* may work ??
beforeSend: function (request) {
       //request.setRequestHeader("Access-Control-Allow-Origin: ", "*")
},*/


Sunday, 21 September 2014

Passing Xrm Object from parent page(CRM) to child


Some times we need open a new window from CRM. This new window can be a window a that you open with a simple simple window.open() code. Or it can be a web resource that you want to open dynamically. Most of the time you need the Xrm object on that child page. I've written two small javascript function to pass Xrm object between parent and master page.

function GetXrmElement() {

                //to check if its an iframe
                var IframeCheck = isIframe();
                if (!IframeCheck) {
                    //support for CRM 4.0
                    if (window.opener != null && window.opener.Xrm != null) {
                        Xrm = window.opener.Xrm;
                    }
                        //CRM 2011 and upwords
                    else if (window.top != null && window.top.opener != null
                        && window.top.opener.parent != null && window.top.opener.parent.Xrm != null) {
                        Xrm = window.top.opener.parent.Xrm
                    }
                    else if (this.parent != null && this.parent.Xrm != null)
                        Xrm = this.parent.Xrm;

                    else if (window.top != null) {
                        Xrm = window.top.Xrm;
                    }


                    else {
                        Xrm = null;
                    }
                }

                else {
                    if (this.parent != null && this.parent.Xrm != null)
                        Xrm = this.parent.Xrm;
                    else if (document.parentWindow != null && document.parentWindow.parent != null && document.parentWindow.parent.Xrm != null)
                        Xrm = document.parentWindow.parent.Xrm;
                    else if (window.top != null)
                        Xrm = window.top.Xrm;
                    else
                        Xrm = null;
                }

                if (Xrm == null)
                    alert("Cannot retrieve Xrm object");
            }

Tuesday, 2 July 2013

CRM 2011: Deploying More Than One Steps using Developer toolkit

Part Two - The Final Steps

On my previous post I have discussed the steps for the preparation needed for creation of creating a plugin which can be used to handle multiple messages. This part will describe the final few steps needed to create the plug in.

For this you need to go to the RegisterFile.crmregister. Locate the tag “Step”. Copy the content of the tag and paste it right underneath the closing of the tag. Notice that it contains MessageName, Mode, PrimaryEntity, Stage and some other attributes. On the new step change attribute MessageName to “Update”. This is how you are telling the package project that you have added another step to the same plugin. The RegisterFile should look like following.


<?xml version="1.0"?>
<Register xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/crm/2011/tools/pluginregistration">
  <Solutions>
    <Solution Assembly="TestSolution.Plugins1.dll" Id="00000000-0000-0000-0000-000000000000" IsolationMode="Sandbox" SourceType="Database">
      <PluginTypes>
        <Plugin Description="Plug-in to InvoiceHandler" FriendlyName="InvoiceHandler" Name="TestSolution.Plugins1.InvoiceHandler" Id="00000000-0000-0000-0000-000000000000" TypeName="TestSolution.Plugins1.InvoiceHandler">
          <Steps>
            <clear />
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="00000000-0000-0000-0000-000000000000" MessageName="Create" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="00000000-0000-0000-0000-000000000000" MessageName="Update" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
          </Steps>
        </Plugin>
      </PluginTypes>
    </Solution>
  </Solutions>
  <XamlWorkflows />
</Register>




Open invoice handler and local the following line.


base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "invoice", new Action<LocalPluginContext>(ExecuteInvoiceHandler)));



Again copy and paste the line just underneath the original line. After that change second parameter to “Update”. Now the lines look like this.


base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "invoice", new Action<LocalPluginContext>(ExecuteInvoiceHandler)));

base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "invoice", new Action<LocalPluginContext>(ExecuteInvoiceHandler)));


That’s it. Just right click the package project and click deploy and the code will be deployed to the server. Finally after deployment the xml file should look like this,

<?xml version="1.0" encoding="utf-8"?>
<Register xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/crm/2011/tools/pluginregistration">
  <Solutions>
    <Solution Assembly="TestSolution.Plugins1.dll" Id="6f5c9e09-58e3-e211-8a00-3c4a92dbdc39" IsolationMode="Sandbox" SourceType="Database">
      <PluginTypes>
        <Plugin Description="Plug-in to InvoiceHandler" FriendlyName="InvoiceHandler" Name="TestSolution.Plugins1.InvoiceHandler" Id="715c9e09-58e3-e211-8a00-3c4a92dbdc39" TypeName="TestSolution.Plugins1.InvoiceHandler">
          <Steps>
            <clear />
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="725c9e09-58e3-e211-8a00-3c4a92dbdc39" MessageName="Create" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="745c9e09-58e3-e211-8a00-3c4a92dbdc39" MessageName="Update" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
          </Steps>
        </Plugin>
      </PluginTypes>
    </Solution>
  </Solutions>
  <XamlWorkflows />
</Register>


Tuesday, 25 June 2013

CRM 2011: Deploying More Than One Steps using Developer toolkit

Part One - Preparation

The general description of how to create and register a plugin with developer toolkit is discussed quite elaborately in msdn.

This post deals with how to deploy more than one steps of a using developer toolkit. Meaning how to design a plug in that will get triggered by more than one event. I will try to put as much sample codes and screen shot possible. Before going into it let us go through the terminology used throughout the post.

Event – Trigger Request, for example Create, Assign, Set State etc. I will be using create and update
Handler – Code snippet that handles an event.
Package Project – CRM 2011 package project that contains reference of all the other crm 2011 projects added to the solution.

At first open visual studio and open the solution you want to use. In this case I have used a blank solution. When the solution is loaded/created right click the solution in the solution explorer and then select add new project. On the search box type CRM the following list appears. Select “Dynamics CRM 2011 Package”, then name your project and then click OK.

For my understanding I always consider the package project as a register where the deployment information for the workflows and plugins are stored. I am sure there is a genius definition of CRM Package. But hey this blog is not for geniuses.

Secondly, right click the solution and click add project again and in the search box type crm.  But this time click “Dynamics CRM 2011 plug-in Library”. This will be the project where all the plug-in handlers for the solution will reside. Up to now we have not written a single line of code. And our solution explorer looks something like following


Now click on the CRM Explorer and then select the entity on which you want to create the handler. In our case we are using Invoice entity. Once the entity is selected, right click it and select Create Plug-in. A window that looks very similar to the screen for registering plug-in step appears. You need to select the Message as well as the correct pipeline stage. Notice that the name of the class on top right of the screen changes as you select the correct pipeline stage and message.


Since we are going to use the same the class on multiple events I have given a generic name to the class. When we click “Ok” button we will see in our plug-in project, a new class named “InvoiceHandler” got created. Also if we click on “RegisterFile.crmregister” in the package project we will see XML similar to the one given below. Notice that all the id fields are now empty guid. They will be replaced with the actual guid once the solution is deployed.  

<?xml version="1.0"?>
<Register xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/crm/2011/tools/pluginregistration">
  <Solutions>
    <Solution Assembly="TestSolution.Plugins1.dll" Id="00000000-0000-0000-0000-000000000000" IsolationMode="Sandbox" SourceType="Database">
      <PluginTypes>
        <Plugin Description="Plug-in to InvoiceHandler" FriendlyName="InvoiceHandler" Name="TestSolution.Plugins1.InvoiceHandler" Id="00000000-0000-0000-0000-000000000000" TypeName="TestSolution.Plugins1.InvoiceHandler">
          <Steps>
            <clear />
            <Step CustomConfiguration="" Name="InvoiceHandler" Description="Post-Operation of Invoice Create" Id="00000000-0000-0000-0000-000000000000" MessageName="Create" Mode="Synchronous" PrimaryEntityName="invoice" Rank="1" SecureConfiguration="" Stage="PostOutsideTransaction" SupportedDeployment="ServerOnly">
              <Images />
            </Step>
          </Steps>
          
        </Plugin>
      </PluginTypes>
    </Solution>
  </Solutions>
  <XamlWorkflows />
</Register>


This concludes our preparation part for the problem. On the next part I will discuss how to use this architecture to register more than one steps (and plug in if necessary) and deploy the solution in one go.


CRM 2011: To “Sandbox” or not to “Sandbox”

Yes I know - My poetry sucks... Today I came up with one of the most intriguing and at the same time foolish question. What does isolation mode in the plugin registration tool mean? The reason the question is intriguing is explained in the following paragraphs. The question becomes foolish because after few years of hardcore crm development this question never strike as something worth knowing.


Long story short - isolation mode while plugin registration defines if a plug in or a workflow is to be run securely in the server. It is also the only way you can register your plugin in crm online however I haven’t tested it. The two option that isolation mode can have are,

None: Meaning plugin/WF is running in unsecured way.
Sandbox: Plugin is running on high security.

Most of the articles you can find about debugging a plugin deal with how to debug plugin registered in normal isolation (None). I will quickly discuss some key reasons and key points of using sandbox isolation.
  • As I have mentioned before if you are working on CRM online then you can only register your plugin in Sandbox isolation. Also if you are using crm on premises but your crm endpoint is hosted is https I suggest you should use Sandbox.
  • Your sandbox plugin is secured which means you cannot access system, logs etc from a sandboxed plugin.
  • If your sandbox plugin becomes stuck (un-responsive) for any reason, the system (worker process) will be more brutal in chopping it off the queue.
  • Most importantly you can debug a sandbox plugin by attaching it to Microsoft.Crm.Sandbox.WorkerProcess.exe instead of normal w3p.exe or CrmAyncService.exe.

Don’t trust me? then check out Slinog or MSDN for more information.