Search This Blog

Wednesday, December 2, 2015

Copy and Paste Plugin Steps and Images from One Plugin to another

Hi ,

I have just created a small tool which will allow you to Copy and Paste Plugin steps and images from one plugin to another.

Image below shows the 2 different plugins with different versions one with steps and images and one without


you need to select plugin with steps and images to be copied and click on "Copy Plugin Steps"


The new window appears which allows you to select the plugin where copied steps and images to be pasted


select the plugin where you need to paste the steps and images and clock on "Paste" button , once successfully copied it will show message


You can refresh the assembly and see all the steps from copied plugin are pasted to new plugin as it is.


Tuesday, December 2, 2014

How to get Display Status of Tab

Below code will return you the display status of tab.

var tabState = Xrm.Page.ui.tabs.get('economyandinformation_tab').getDisplayState();

It will return you the tab status in below format (expanded or collapsed)
 

Monday, December 1, 2014

Cloning Microsoft CRM Records

Hi Below is the way you can create a multiple copies of any record of any entity.
 
Let say I have 1 record of contact which I need to make close
 
// Parent Contact Record
 
Entity oldcontact = crmservice.Retrieve("contact", ContactId,new ColumnSet(true));

// Child Contact Record
 
Entity newcontact;

newcontact = oldcontact.Clone(true);

newcontact.Attributes.Remove("contactid"); // This is very important step in cloning as you have to avoid duplicate primary key error.

newcontact.Id = Guid.NewGuid(); // create new GUID for new record


crmservice.Create(newcontact);

And you will get a copy of parentcontact record into childcontact

Enjoy.
 

Friday, November 28, 2014

How to read OptionSet Attribute in MS CRM 2011/13

Following is the code on how to read OptionSet Value into Array in JavaScript

function GetMultiSelectOptions(id) {
   
    var optionsArray = new Array();
    var options = Xrm.Page.getAttribute("ap_postprofiletasks").getOptions();  // Read OptionSet Field
    if (options && options.length)
    {
        for (var i = 0; i < options.length; i++) {
            var option = options[i];
            if (option.value && option.text) {
                if (option.value == 778210006) {
                    alert(option.text);
                    optionsArray.push({ text: option.text, value: option.value });
                }
            }
        }
       
    }
    return optionsArray;
}

using OData in Javascript MS CRM 2013


Here is code  for how to fetch entity records from JavaScript Using OData
use Schema names for field names

function MainFunction()
{
    var project = getLookupId("ap_project");
    if (project != null) {
        var filter = "&$filter=";
        filter += "ap_projectId eq guid'" + project + "'";
        var odataQuery = "/ap_projectSet?$select=ap_projectId,ap_TypeOfContract" + filter;
        ExecuteQuery(odataQuery, true, function (data) {
            if (data && data.d && data.d.results && data.d.results[0])
           {
               // Get Results here
                       var typeofcontract = data.d.results[0].yourfieldname.Value;
              
            }
        });
    }
}

function ExecuteQuery(odataQuery, sync, callback) {
    var async = true;
    if (sync) {
        async = false;
    }
    var odataPath = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc";
    var odataUrl = odataPath + odataQuery;
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odataUrl,
        async: async,
        beforeSend: function (xmlHttpRequest) {
            xmlHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, xmlHttpRequest) {
            if (callback) {
                callback(data);
            }
        },
        error: function (xmlHttpRequest, textStatus, errorObject) {
            alert("Error Occurred : " + textStatus + ": " + JSON.parse(xmlHttpRequest.responseText).error.message.value);
        }
    });
}

function getLookupId(lookupName) {
    var lookupItem = new Array();
    lookupItem = Xrm.Page.getAttribute(lookupName).getValue();
    if (lookupItem != null) {
        return lookupItem[0].id;
    }
    else
        return null;
}

Friday, February 7, 2014

Using Xrm.Utility.openEntityForm with Parameters

Below is a code which will show how to open new Entity Record and pass parameter to the new form while opening

    var phone1 = Xrm.Page.getAttribute("ap_phone1").getValue();
    var phone2 = Xrm.Page.getAttribute("ap_phone2").getValue();
    var phone3 = Xrm.Page.getAttribute("ap_phone3").getValue();
    var phonetype1 = Xrm.Page.getAttribute("ap_phone1type").getValue();
    var phonetype2 = Xrm.Page.getAttribute("ap_phone2type").getValue();
    var phonetype3 = Xrm.Page.getAttribute("ap_phone3type").getValue();

   var parameters = {};

    parameters["ap_phone1"] = phone1;
    parameters["ap_phone2"] = phone2;
    parameters["ap_phone3"] = phone3;
    parameters["ap_phone1type"] = phonetype1;
    parameters["ap_phone2type"] = phonetype2;
    parameters["ap_phone3type"] = phonetype3;

// Opening New Record of "ap_profiling" entity , if you want to open existing record please pass recordID instead of Null in 2nd parameter



  Xrm.Utility.openEntityForm("ap_profiling", null, parameters);

Wednesday, January 29, 2014

Adding MultiSelect CheckBox on MS CRM 2011 Form

Following steps to create multi select checkbox control on MS CRM 2011 form.

1. Create a picklist fields with required options and add it to your CRM form.
2. this picklist field will be converted to checkbox control at runtime.
3. you need to create one more text field in CRM and place it on the form in hidden mode , this field is required to store and read values selected in CheckBox Control.

Call the function below on load of the form

in the below example  "ap_typeofbuilding" is my Picklist control which will be converted to CheckBox Control for Multi select options , and "ap_btypetext" is my text field to read and store values selected in checkbox control.



gMultiSelectBTList = function () {

    // PL - the picklist attribute; PLV - used to save selected picklist values 

    var PL = document.getElementById("ap_typeofbuilding");
    var PLV = document.getElementById("ap_btypetext");

    var picklist = "ap_typeofbuilding";
    var textfield = "ap_btypetext";

    if (!PLV || textfield == '') { PLV = null; }
    if (PL != null) {

        PL.style.display = "none";

        //PLV1.style.display = "none"; 

        // Create a DIV container 

        var addDiv = document.createElement("<div style='overflow-y:auto; height:80px; border:1px #6699cc solid; background-color:#ffffff;' />");

        //  var addDiv1 = document.createElement("<div style='overflow-y:auto; height:80px; border:1px #6699cc solid; background-color:#EAF3FF;' />"); 

        PL.parentNode.appendChild(addDiv);

        // Initialise checkbox controls 

        for (var i = 1; i < PL.options.length; i++) {
            var pOption = PL.options[i];

            if (!IsChecked(pOption.text))

                var addInput = document.createElement("<input type='checkbox' name=" + pOption1.text + " value=" + pOption1.value + " style='border:none; width:25px; align:left;' onclick='picklistOnClick(" + picklist + "," + textfield + ")' />");

            else

                var addInput = document.createElement("<input type='checkbox' name=" + pOption1.text + " value=" + pOption1.value + " checked='checked' style='border:none; width:25px; align:left;' onclick='picklistOnClick(" + picklist + "," + textfield + ")' />");

            var addLabel = document.createElement("<label />");

            addLabel.innerText = pOption.text;

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



            PL.nextSibling.appendChild(addInput);
            PL.nextSibling.appendChild(addLabel);
            PL.nextSibling.appendChild(addBr);

        }



        // Check if it is selected 

        function IsChecked(pText) {

            if (!PLV) return;

            if (PLV.value != "") {

                var PLVT = PLV.value.split("|");

                for (var i = 0; i < PLVT.length; i++) {

                    if (PLVT[i] == pText)

                        return true;

                }

            }

            return false;

        }

        picklistOnClick = function (oPL, oPLV) {

            if (!oPLV) return;

            oPLV.value = "";

            var getInput = oPL.nextSibling.getElementsByTagName("input");

            for (var i = 0; i < getInput.length; i++) {
                if (getInput[i].checked) {

                    oPLV.value += getInput[i].nextSibling.innerText + "|";
                }

            }

            //MUST DO THIS TO TRIGGER A SAVE EVENT

            var btypetext = Xrm.Page.data.entity.attributes.get("ap_btypetext");
            btypetext.setValue(PLV.value);

        }

    }

}

This is another function which will help you to read selected values in text field and selected them in CheckBox Control ( this is for existing records )

function ReadBTPickList()
{
    var PL = crmForm.all.ap_typeofbuilding;
    var getInput = PL.nextSibling.getElementsByTagName("input");
    var allbtype = Xrm.Page.getAttribute("ap_btypetext").getValue();
    if (allbtype != null) {
        var btype = allbtype.split('|');

        for (var i = 0; i < btype.length - 1; i++) {
            for (var j = 0; j < getInput.length - 1; j++) {
                if (getInput[j].name == btype[i]) {
                    getInput[j].checked = true;
                }
            }
        }

    }
}