RSS

Category Archives: WebResources

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

Advertisements
 

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: , , , , , , , , , , , , , , , , ,

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: , , , , , , , , , , , , , , , , , , , , , ,

How to append Email Template to Email Entity Form on Load through JavaScript

Introduction

Generally, we add a Signature at the bottom of Email before we send. One of my projects needed the same requirement. We need to insert one Signature Email Template into the description body of Email Form on form load. I have found a solution and now I am going to describe it.

Steps

  1. Create a web resource of Script type and add to the Email Form library
  2. Add the “AddSignatureToEmail” function to the form “onload” event
  3. Create a Email Template containing Signature body and copy the Template Id
  4. Replace that Template Id in the following code for variable “emailTemplateToLoad

Code

Following is the Code snippet.

function AddSignatureToEmail() {
	// Check the form type should be 'create' type
	if (Xrm.Page.ui.getFormType() != 1) { return; }

	// Pre-fill a template signature
	var drawSignature = false;
	var emailTemplateToLoad = "b348fc8b-1e6e-e311-9d64-6c3be5a86df8 "; //created email template Id

	// Check if description is blank or similar
	var theDescription = Xrm.Page.getAttribute("description").getValue();
	if (theDescription == null) {
		drawSignature = true;
	} else if (theDescription == undefined) {
		drawSignature = true;
	} else if (stripHTML(theDescription) == "") {
		drawSignature = true;
	} else if (stripHTML(theDescription).length < 10) {
		drawSignature = true;
	}

	if (drawSignature) {
		// Get Regarding object details
		var regardingobjectid = Xrm.Page.getAttribute("regardingobjectid");
		if (regardingobjectid==undefined) { return; }
		var RegardingItems = Xrm.Page.getAttribute("regardingobjectid").getValue();

		// The signature will not append if regarding field remains blank.
		if (RegardingItems!=null) {
			var regardingObjectId = RegardingItems[0].id;
			var regardingObjectType = RegardingItems[0].type;

			if (regardingObjectId == null || regardingObjectId == "") { return; }
			if (regardingObjectType == null || regardingObjectType == "") { return; }

			// Retrieving email template details

			var command = new RemoteCommand("EmailTemplateService", "GetInstantiatedEmailTemplate");
			command.SetParameter("templateId", emailTemplateToLoad);
			command.SetParameter("objectId", regardingObjectId);
			command.SetParameter("objectTypeCode", regardingObjectType);
			var result = command.Execute();

			if (result.Success) {
				var o = new Object();
				o.EmailBody = "";
				o.EmailSubject = "";
				if (typeof (result.ReturnValue) == "string") {
					// Create a Xml Document of the return value to retrieve actual data
					oXml = CreateXmlDocument(result.ReturnValue);
					o.EmailBody = oXml.lastChild.lastElementChild.textContent;

					Xrm.Page.getAttribute("description").setValue(o.EmailBody);
				}
			}
		}	
	}
}

function stripHTML(signature) {
	var tmp = document.createElement("DIV");
	tmp.innerHTML = signature;
	return tmp.textContent || tmp.innerText;
}

function CreateXmlDocument(signatureXmlStr) {
    // Function to create Xml formate of return email template data
	var parseXml;

	if (window.DOMParser) {
		parseXml = function (xmlStr) {
			return (new window.DOMParser()).parseFromString(xmlStr, "text/xml");
		};
	}
	else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) {
		parseXml = function (xmlStr) {	
			var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async = "false";
			xmlDoc.loadXML(xmlStr);
			
			return xmlDoc;
		};
	} 
	else {
		parseXml = function () { return null; }
	}

	var xml = parseXml(signatureXmlStr);
	if (xml) {
		return xml;
	}
}

var a = window.setTimeout(AddSignatureToEmail, 1500);

By Sukanta Mangal
Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
3 Comments

Posted by on January 13, 2014 in WebResources

 

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

CRM 2013 – Refresh Associated Grid of an Entity

Introduction

Today I got a requirement to add a custom Ribbon Button in the SubGrid of Marketing List Entity and execute some logic and refresh the Grid. Last point was the trickiest one for me and that is why I decided to share the approach how to do it.

Steps

To achieve this, let’s go step by step.

Step-1: Create a JavaScript library that will be executed when Button is Clicked

function OpenLookUp(grid){
    //your logic

    //code that will refresh the grid
    grid.refresh();
}

Step-2: Add Custom Button using Ribbon Workbench and follow the Screen Shots

img1

img4
Select WebResource

Add the Selected Control as parameter.
img3

Step-3: Publish Solutions using Ribbon Workbench

Now the view will refresh after the Button is clicked.

By Puja Jain
Senior Software Engineer @Team DynamicsCRM.
Mindfire Solutions

 
2 Comments

Posted by on December 27, 2013 in WebResources

 

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

 
%d bloggers like this: