Menu Close

Blog

Microsoft Business Applications Blogposts, YouTube Videos and Podcasts

Helping Businesses with Technology

Microsoft Business Applications Blogposts, YouTube Videos and Podcasts

Helping Businesses with Technology

Microsoft Business Applications Blogposts, YouTube Videos and Podcasts

Helping Businesses with Technology

previous arrow
next arrow
Slider

RealTime Scenario

1. > Create 4 contact record. (A,B,C,D)
2. > 3(B,C,D) Contact record will be child of 1(A-Parent)
3. > When ever A-Parent information will be changed should be refelected to their respective child also. -plugin/Jscript
4. > Selection of parent lookup — Data wil be fetch through Jscript OData.
Description
———–
Optionset value -> Parent/Child

[ If parent is selected from parent/child field then parent field and parent section fields parentemail and parentphonenumber will be disabled]
[ if child is selected from parent/child field then parent field should be required field and the parent section fields parentemail and parentphonenumber should be
auto populated from parent record].

Create new entity Donation
create fields
————-
parent/child = optionset = parent, child(business required field)
parent = lookup to itself
emailaddress = text field
phonenumber = phonenumber
gender = optionset= male/female
companyname = text field
designation = text field
city = text field
country = lookup to country entity//(in the country entity only add country field)

CREATE NEW SECTION CALLED PARENT SECTION LABEL(TWO COLUMN)
Fields
—–
parentemail = text field
parentphonenumber = text field

======================================================================
Javascript  is as follows:

function FormOnLoad() {
    /*For Type
    0 -Undefined
    c  1- Create
    u 2-Update
    r 3-ReadOnly
    d 4 -Disabled
    */
    var type = Xrm.Page.ui.getFormType();
    Xrm.Page.getControl(“new_parentemail”).setDisabled(true);
    Xrm.Page.getControl(“new_parentphonenumber”).setDisabled(true);
    if (type == 1) {//Create Mode
        //TODO : by default optionset value will be parent and parent lookup should be disabled.
        var optionSet = Xrm.Page.data.entity.attributes.get(“new_parentchildoptionset”);
        optionSet.setValue(100000000);
        Xrm.Page.getControl(“new_parent”).setDisabled(true);

    } else {
        var parentChildOptionSet = Xrm.Page.data.entity.attributes.get(“new_parentchildoptionset”);
        if (parentChildOptionSet != null) {
            var optionsetvalue = parentChildOptionSet.getValue();
            // this for parent
            if (optionsetvalue == 100000000) {
                Xrm.Page.getAttribute(“new_parent”).setRequiredLevel(“none”);
                Xrm.Page.getControl(“new_parent”).setDisabled(true);
             
            } else if (optionsetvalue == 100000001) {
                Xrm.Page.getControl(“new_parent”).setDisabled(false);
                //Setting the required filed
                Xrm.Page.getAttribute(“new_parent”).setRequiredLevel(“required”);
            }
        }
    }

}
function OnChange_ParentChildOptionSet() {
   
    var optionsetvalues = Xrm.Page.data.entity.attributes.get(“new_parentchildoptionset”);
    var optionsetvalue = optionsetvalues.getValue();
    // this for parent
    if (optionsetvalue == 100000000) {
        Xrm.Page.getAttribute(“new_parent”).setRequiredLevel(“none”);

        Xrm.Page.getControl(“new_parent”).setDisabled(true);

    } else if (optionsetvalue == 100000001) {//Child
        Xrm.Page.getControl(“new_parent”).setDisabled(false);
        Xrm.Page.getAttribute(“new_parent”).setRequiredLevel(“required”);
    }

}
function OnChange_ParentLookup() {
    var parentlookup = Xrm.Page.getAttribute(“new_parent”).getValue();
    if (parentlookup != null) {
        var lookupId = parentlookup[0].id;
        var CrmServerUrl;
        if (typeof GetGlobalContext != “undefined”) {
            CrmServerUrl = GetGlobalContext().getClientUrl();
        } else {
            if (typeof Xrm != “undefined”) {
                CrmServerUrl = Xrm.Page.context.getClientUrl();
            } else {
                alert(“Context is not available.”);
            }
        }
        if (CrmServerUrl.match(//$/)) {
            CrmServerUrl = CrmServerUrl.substring(0, Crm.length – 1);
        }

        //REST SERVICE WITH ODATA.
        var oDataPath = CrmServerUrl + “/XRMServices/2011/OrganizationData.svc”;
        var fetchData = new XMLHttpRequest();
        var Odata = oDataPath + “/new_donationSet?$select=new_phonenumber,EmailAddress&$filter=new_donationId eq (guid'” + lookupId + “‘)”;
        fetchData.open(“GET”, Odata, false);
        fetchData.setRequestHeader(“Accept”, “application/json”);
        fetchData.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
        fetchData.onreadystatechange = function () { retrieveParentDetails(this); };
        fetchData.send();

    }
}
retrieveParentDetails = function (fetchData) {
    if (fetchData.readyState == 4) {
     
        var fetchD = this.parent.JSON.parse(fetchData.responseText).d;
       
        if (fetchD.results.length > 0) {
            var phoneNumber = fetchD.results[0].new_phonenumber;
            var email = fetchD.results[0].EmailAddress;
            Xrm.Page.getAttribute(“new_parentphonenumber”).setValue(phoneNumber);
            Xrm.Page.getAttribute(“new_parentemail”).setValue(email);
        }
    }
}

Share this:

REMOTE DEBUGGING MICROSOFT DYNAMICS CRM PLUGINS

Remote Debug the Microsoft Dynamics crm plugin

 
Here is the Screen shot of Remote debug the ms crm 2011 pugin
 
 
 
Here is a  nice video about the Remote debug the ms crm online 2015
 
 
Here is step by step remote debug of ms crm plugin
 
Share this:

SHARED VARIABLES IN MS CRM 2011

Shared Variables in Microsoft Dynamics crm 2011

 
Here is the nice explaination  from Microsoft MSDN Article

The message pipeline model for Microsoft Dynamics CRM defines a parameter collection of custom data values in the execution context that is passed through the pipeline and shared among registered plug-ins, even from different 3rd party developers.

 This collection of data can be used by different plug-ins to communicate information between plug-ins and enable chain processing where data processed by one plug-in can be processed by the next plug-in in the sequence and so on.

This feature is especially useful in pricing engine scenarios where multiple pricing plug-ins pass data between one another to calculate the total price for a sales order or invoice. Another potential use for this feature is to communicate information between a plug-in registered for a pre-event and a plug-in registered for a post-event.

The name of the parameter that is used for passing information between plug-ins is SharedVariables. This is a collection of keyvalue pairs. At run time, plug-ins can add, read, or modify properties in the SharedVariables collection. This provides a method of information communication among plug-ins.
This sample shows how to use SharedVariables to pass data from a pre-event registered plug-in to a post-event registered plug-in.

 
using System;

// Microsoft Dynamics CRM namespace(s)
using Microsoft.Xrm.Sdk;

namespace Microsoft.Crm.Sdk.Samples
{
    /// <summary>
    /// A plug-in that sends data to another plug-in through the SharedVariables
    /// property of IPluginExecutionContext.
    /// </summary>
    /// <remarks>Register the PreEventPlugin for a pre-operation stage and the
    /// PostEventPlugin plug-in on a post-operation stage.
    /// </remarks>
    public class PreEventPlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

            // Create or retrieve some data that will be needed by the post event
            // plug-in. You could run a query, create an entity, or perform a calculation.
            //In this sample, the data to be passed to the post plug-in is
            // represented by a GUID.
            Guid contact = new Guid(“{74882D5C-381A-4863-A5B9-B8604615C2D0}”);

            // Pass the data to the post event plug-in in an execution context shared
            // variable named PrimaryContact.
            context.SharedVariables.Add(“PrimaryContact”, (Object)contact.ToString());
        }
    }

    public class PostEventPlugin : IPlugin
    {
        public void Execute(IServiceProvider serviceProvider)
        {
            // Obtain the execution context from the service provider.
            Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
                serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

            // Obtain the contact from the execution context shared variables.
            if (context.SharedVariables.Contains(“PrimaryContact”))
            {
                Guid contact =
                    new Guid((string)context.SharedVariables[“PrimaryContact”]);

                // Do something with the contact.
            }
        }
    }
}

It is important that any type of data added to the shared variables collection be serializable otherwise the server will not know how to serialize the data and plug-in execution will fail.

For a plug-in registered in stage 20 or 40, to access the shared variables from a stage 10 registered plug-in that executes on create, update, delete, or by a RetrieveExchangeRateRequest, you must access the ParentContext.SharedVariables collection. For all other cases, IPluginExecutionContext.SharedVariables contains the collection.

Share this: