RSS

CRM 2013 Manipulate Look up to show Multiple Entity Record

Introduction

Sometimes, we need to show multiple Entity record in the Look up of single Entity Look up in CRM 2013 like the Picture shown below. This Look up Dialog Box shows the record of two Entities, but the Look up is only of Contact

Two Entity Look Up

Solution

We can achieve this function by following code.

//Setting the lookup type
document.getElementById(LookUp_Logical_Name + "_i")
        .setAttribute("lookuptypes", 
                      "<EntityTypeCode of Entities to be shown in the look up>");

//Setting the lookup name Ex :- account:1:Account,contact:2:Contact
document.getElementById(LookUp_Logical_Name + "_i")
        .setAttribute("lookuptypenames", 
                      "[<Logical name>:<EntityTypeCode>:<Schema Name of Entity>]");

//Setting the lookup icon  Ex:-/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif
document.getElementById(LookUp_Logical_Name + "_i")
        .setAttribute("lookuptypeIcons", 
                      "/_imgs/ico_16_<EntityTypeCode>.gif");

// default type - Account entity To set the default entity
document.getElementById(LookUp_Logical_Name + "_i")
        .setAttribute("defaulttype", 
                     "<EntityTypeCode>");

By Sukant Shekhar
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , , , , ,

CRM 2013 Open Entity Form in new Window by JavaScript

Introduction

During our customization in CRM, we need to open one Entity Form by JavaScript in a new Window.

Problem

By using Xrm.Utility.openEntityForm, it opens the record page in the same page or opens the record in a new Form.

Solution

To open the record in the new Window or to open in a new Dialog, we can use the following code

Note: Please give the Logical Name as Record Type is not taken in CRM 2013

function OpenRecords(Record_Id, Logical_Name_Of_Entity) {
    var reletivePath = "main.aspx?etn=" + Logical_Name_Of_Entity;
    reletivePath = reletivePath + "&pagetype=entityrecord&id=";

    var height = 1300; // Height of the Record Page.
    var width = 900; // Width of the Record Page.
    var windowName = "_blank";
    var serverUrl = Xrm.Page.context.getServerUrl();
    var nAgt = navigator.userAgent;

    if (serverUrl != null && serverUrl != "" 
                      && 
        Record_Id.replace("{", "").replace("}", "") != null)
    {
        serverUrl = serverUrl + reletivePath;
        serverUrl = serverUrl + Record_Id.replace("{", "").replace("}", "");
         
        if (nAgt.indexOf("Firefox") != -1) {
            window.open(serverUrl);
        } else {
            OpenStdWin(serverUrl, 
                       null, 
                       height, 
                       width, 
                       "titlebar=yes, resizable=yes");
        }
    }
}

By Sukant Shekhar
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , , ,

CRM 2013 JqGrid Theme

Behind the Scene

We built a Grid using a jqgrid Plugin in JavaScript for CRM 2011. That time the theme of the jqgrid was matching the CRM theme. But when we moved the solution to CRM 2013, the Grid was looking an odd one out as CRM 2013 Look and Feel was different.

Experiment

I tried to change the CSS of jqgrid and match it with the theme of CRM 2013, but found some problem with it. Then we have to remove the CSS used for the Grid and build a new CSS file for 2013.

Solution

The CSS, which were removed from the HTML page :-
1. jquery-ui-1.7.1.custom.css
2. ui.jqgrid.css (given in the jqGrid Plugin folder)

The CSS newly added for CRM 2013 is :- ui.jqgrid_custom.css (Custom build)
Feel free to click and download the CSS file and implement in your CRM projects.

Previously the Look was

jqPrevious

Now it has been Transformed to

jqGrid New

By Sukant Shekhar
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
 

Tags: , , , , , , , , , , , , , , ,

Open Dialog box like CRM 2013

Introduction

In this Blog, we will explore how to open a Dialog Box similar with CRM 2013 look and feel.

Background

Sometimes, we need to open the custom WebResource in a Dialog Box. But the Dialog Box should look like other Dialog Box in CRM 2013.

Custom Dialog Box

Solution

We can achieve this by one CRM function in the following way:

Note: Here, URL must be without Server URL.

For the Parent Window:

var DialogOption = new Xrm.DialogOptions;
DialogOption.width = <Height>; DialogOption.height = <width>;

Xrm.Internal.openDialog(<Relative_Url_of_the_Webresource>, 
                        DialogOption, 
                        null, null, 
                        CallbackFunction);

function CallbackFunction(returnValue){ }

In the Dialog Box, please include:

<script type="text/javascript" 
        src="../../../../../../webresources/ClientGlobalContext.js.aspx"></script>
/*This Might change according to the url*/

And

//Pass the return Value to the parent window
Mscrm.Utilities.setReturnValue(oReturn);

try {
    closeWindow(true);//Close the dialog box
}
catch (e) { }

By Sukant Shekhar
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , ,

Use of Shared Variables in Plugin

Introduction

Shared Variables will be useful for sharing the data during complex Plug-in development by sharing the data between Plugins registered on both the pre and post events.

Any value stored in the Plug-in context of Pre-event will be available in the Post-event of the Plug-in. This way, we can avoid storing the values in a custom attribute. Certain data validation which needs to be done at post-event can be achieved by passing the value from Pre-event of the Plug-in. This also helps for performing business logic like updating related records asynchronously.

Using the Code

The below code snippet illustrates the usage of Shared Variable. This sample explains the data validation done at Post-event operation based on the value received from the Pre-event operation where a flag is updated with a value at the Pre-event level and sent to the Post-event through shared variable.

//Pre-Create (Entity Name) Plug-in
if (pluginContext.MessageName == "Create")
{
    if (pluginContext.InputParameters.ContainsKey("Target")
                             && 
        pluginContext.InputParameters["Target"] is Entity)
    {
        Entity targetEntity = context.InputParameters["Target"] as Entity;
        if (targetEntity != null)
        {
            bool setFlag = false;

            //Check data validation for attributes
            string country = targetEntity.Attributes["address1_country"];
            OptionSetValue industryCode = (OptionSetValue)target.Attributes["industrycode"];

            // Country is US and Industry Type is Accounting are Preferred
            if (country.ToLower() == "us" && industryCode.Value == 1)
            {
                setFlag = true;
            }
            
            pluginContext.SharedVariables.Add("flag", setFlag);
        }
    }
}

//Post-Create (Entity Name) Plug-in
if (pluginContext.MessageName == "Create")
{
    if (pluginContext.InputParameters.ContainsKey("Target")
                           && 
        pluginContext.InputParameters["Target"] is Entity)
    {
        Entity targetEntity = pluginContext.InputParameters["Target"] as Entity;
        if (targetEntity != null)
        {
            if (pluginContext.SharedVariables.ContainsKey("flag"))
            {
                bool recievedFlag = (bool)pluginContext.SharedVariables["flag"];
                if (recievedFlag)
                {
                    // Do whatever you want to do
                }
             }
         }
    }
}

This method lets you to pass data between Plug-ins without having to customize the system by creating hidden fields on entities.

Note: SharedVariables (collection of key/value pairs) property is available in the IPluginExecutionContext of the execution pipeline.

By Gitanjali
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , , ,

Cascade Relationship Behavior in Microsoft Dynamics CRM

Introduction

This Blog is all about out-of-the-box Cascade Relationship Behavior and how to use it in more efficient way as per the business.

Default Behavior:

When an Account record “Company1, Inc.” is reassigned to another owner “User2” from “User1” then as per the default “Parental Relationship Behavior” all the completed and open child records i.e. Contacts, Opportunities, cases, Tasks, Emails, Phones calls, etc. are also reassigned to the another owner “User2“, but the important point here is to keep the completed Entities and Activities records impaired in any way to avoid confusions in future.

Image

Is there a workaround for this?

Yes, to change this setting, here are few simple steps:

  1. Go to “CRM >> Settings >> Customization >> Customize the System >> Account >> 1: N Relationships”.

    Image

  2. Open the desire relationship record and change the “Type of Behavior” from “Parental” to “Configurable Cascading“.

    Image

  3. Now often we think of the meaning of these behaviors i.e. Cascade Active/Cascade User-Owned/Cascade None.
    • Cascade Active: means owner will change only if record is Active.
    • Cascade User-Owned: means owner will change only if the related record owner is same as Parent record.
    • Cascade None: means owner will not change.
  4. So, as I explained above, to avoid confusion in future about the completed records we just need to change the “Assign” field value from “Cascade Relationship Behavior” to “Cascade Active“.

    Image

By Abhisek Sriramka
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 

Tags: , , , , , , , , , , , , , , , , , , , , , , , ,

CRM 2013 Multi Pick List

Background

In One of our previous Blogs CRM 2011 Multi Pick list, we have discussed about creating Multiple Pick List in the MS Dynamic CRM form. But the previous post was for CRM 2011. As the CRM 2013 is supported across different browsers, we have to change a little in the code to make it compatible for all major browsers. Here is the modified Blog for Multi Pick List in MS Dynamics CRM 2013.

Let’s start

In this article, we will create a Multiple Pick List for Dynamic CRM form. User can enter multiple data from Pick List by CheckBox. This will also work on all the four major browsers (IE, Firefox, Chrome and Safari).
5-1-2013 1-35-04 PM

Requirement

There was a requirement in a project, where user wanted to select, not only one, but also multiple value from a Pick List.

Solution

Steps which are needed to be followed:-

  1. Creation of Field.
  2. Create Web Resource.
  3. Add function to the form.

Creation of Field

There are two fields which are created on the entity you want to make Multi Pick List :-

  1. OptionSet Field :- all the option which must be entered
  2. Data Field:- Multiple Lines of Text Field. In which data is stored.

Include both the field on the form.

Create Web Resource

Create a Web Resource with the following code:-

// var_sc_optionset >>  Provide logical-name for Option Set field
// var_sc_optionsetvalue >> Provide logical-name for field which will
//                          store the multi selected values for Option Set
// OS >> Provide Options of the Optionset field
//       (Ex:- Xrm.Page.getAttribute("Option Set field logical-name").getOptions())
// OSV >> Provide text field object which will store the
//        multi selected values for Option Set
//       (Ex:- document.getElementById("text field logical-name"))

// Method to convert an optionset to multi select OptionSet
function ConvertToMultiSelect(var_sc_optionset, var_sc_optionsetvalue, OS, OSV) {

    if (OS != null && OSV != null) {

        document.getElementById(var_sc_optionset).style.display = "none";

        // Create a DIV container
        var addDiv = document.createElement("div");
        addDiv.id = var_sc_optionsetvalue + "_m";
        addDiv.style.width = "100%";
        addDiv.style.height = "80px";
        addDiv.style.background = "#ffffff";
        addDiv.style.color = "white";
        addDiv.style.overflow = "auto";
        addDiv.style.border = "1px #6699cc solid";
        document.getElementById(var_sc_optionset).parentNode.appendChild(addDiv);

        // Declaration of variables will be used in the loop depending upon the browser
        var initialValue = 0;
        var maxValue = 0;

        var nAgt = navigator.userAgent;

        if (nAgt.indexOf("Firefox") != -1) {  // If the broswer is "Firefox" 

            initialValue = 1;
            maxValue = OS.length;

        }
        else if (nAgt.indexOf("Chrome") != -1 || nAgt.indexOf("IE") != -1) { // If the browser is Chrome or IE

            initialValue = 0;
            maxValue = OS.length - 1;
        }
        else if (nAgt.indexOf("Safari") != -1) {  // If the browser id "Safari"

            initialValue = 1;
            maxValue = OS.length;
        }

        // Initialise checkbox controls
        for (var i = initialValue; i < maxValue; i++) {
            var pOption = OS[i];
            if (!IsChecked(pOption.value, var_sc_optionsetvalue)) {
                var addInput = document.createElement("input");
                addInput.type = "checkbox";
                addInput.style.border = "none";
                addInput.style.width = "25px";
                addInput.style.align = "left";
                addInput.style.color = "#000000";
                addInput.onclick = function () {

                    OnSave(var_sc_optionset, var_sc_optionsetvalue);
                    createTable(var_sc_optionsetvalue);
                }
            }
            else {

                var addInput = document.createElement("input");
                addInput.type = "checkbox";
                addInput.checked = true;
                addInput.setAttribute("checked", true);
                addInput.checked = "checked";
                addInput.defaultChecked = true;
                addInput.style.border = "none";
                addInput.style.width = "25px";
                addInput.style.align = "left";
                addInput.style.color = "#000000";
                addInput.onclick = function () {

                    OnSave(var_sc_optionset, var_sc_optionsetvalue);
                    createTable(var_sc_optionsetvalue);
                }

            }

            //Create Label
            var addLabel = document.createElement("label");
            addLabel.style.color = "#000000";
            addLabel.innerHTML = pOption.text;

            var addBr = document.createElement("br"); // it's a 'br' flag

            document.getElementById(var_sc_optionset).nextSibling.appendChild(addInput);
            document.getElementById(var_sc_optionset).nextSibling.appendChild(addLabel);
            document.getElementById(var_sc_optionset).nextSibling.appendChild(addBr);
        }
    }
}

// Check if it is selected
function IsChecked(pText, optionSetValue) {

    var selectedValue = Xrm.Page.getAttribute(optionSetValue).getValue();

    if (selectedValue != "" && selectedValue != null) {
        var OSVT = selectedValue.split(",");

        for (var i = 0; i < OSVT.length; i++) {
            if (OSVT[i] == pText)
                return true;
        }
    }

    return false;
}

// var_sc_optionsetvalue >> Provide logical-name for field which will
//                          store the multi selected values for Option Set
// optionSet>> Provide logical-name of Option Set field 
function OnSave(optionSet, var_sc_optionsetvalue) {

    var OS = document.getElementById(optionSet);
    var options = Xrm.Page.getAttribute(optionSet).getOptions();
    var getInput = OS.nextSibling.getElementsByTagName("input");
    var result = "";
    var result1 = "";
    var nAgt = navigator.userAgent;

    for (var i = 0; i < getInput.length; i++) {
        if (getInput[i].checked) {
            result += getInput[i].nextSibling.innerHTML + ",";

            if (nAgt.indexOf("Firefox") != -1) {  //If the broswer is "Firefox"
                result1 += options[i + 1].value + ",";
            }

            else if (nAgt.indexOf("Chrome") != -1 || nAgt.indexOf("IE") != -1) { //If the browser is Chrome or IE

                result1 += options[i].value + ",";
            }

            else if (nAgt.indexOf("Safari") != -1) {  //If the browser id "Safari"

                result1 += options[i + 1].value + ",";

            }

        }
    }

    //save value
    Xrm.Page.getAttribute(var_sc_optionsetvalue).setValue(result1);
}

// var_sc_optionsetvalue >> Provide logical-name for field which will
//                          store the multi selected values for Option Set
function createTable(var_sc_optionsetvalue) {
    // Get OptionSet value
    var OptionValue = Xrm.Page.getAttribute(var_sc_optionsetvalue);
    var c_OptionValue = Xrm.Page.getControl(var_sc_optionsetvalue);
    var d_OptionValue = var_sc_optionsetvalue + "_d";

    if (OptionValue.getValue() != null) {

        var OptionValueHtml = "<div style=\"overflow-y:auto;width:100%;display: none; min-height: 5em; max-height: 1000px;\">";

        OptionValueHtml += "<table style='width:100%;height: 100%;'>";
        var OptionValueV = OptionValue.getValue();

        var OptionValueT = OptionValueV.split(",");
        var cols = 0;
        for (var row = 0; row < OptionValueT.length - 1; row++) {
            OptionValueHtml += "<tr  style='height:20px;'>";
            for (var i = cols; i < cols + 3; i++) {
                OptionValueHtml += "<td style='width:33%;'>";
                if (OptionValueT[i] != null || OptionValueT[i] != undefined) {

                    OptionValueHtml += OptionValueT[i];
                }
                OptionValueHtml += "</td>";
            }
            cols = cols + 3;
            OptionValueHtml += "</tr>";
            if (cols >= OptionValueT.length) {
                break;
            }
        }

        OptionValueHtml += "</table>";
        OptionValueHtml += "</div>";
        document.getElementById(d_OptionValue).innerHTML = OptionValueHtml;
    }  
}

Add function to the form

There are three functions need to be added

  • On Load :-

    1. Function name :- ConvertToMultiSelect.
      Parameter :- “new_multipicklistoption”, “new_multipicklistvalue”, Xrm.Page.getAttribute(“new_multipicklistoption”).getOptions(), document.getElementById(“new_multipicklistvalue”)
    2. Function name :- createTable
      Parameter :- “new_multipicklistvalue”.

5-1-2013 1-11-58 PM

  • On Save :-

    1. Function Name :- OnSave
      Parameter :- “new_multipicklistoption”, “new_multipicklistvalue”

5-1-2013 1-12-52 PM

Reference

CRM 2011 Multi Pick list

By Ranjan Parhi
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
2 Comments

Posted by on January 30, 2014 in WebResources

 

Tags: , , , , , , , , , , , , , , , , , , , , , ,

 
%d bloggers like this: