Tags

CRM & Technology Management


Sales and Marketing Advisor


Sign Up For the Newsletter

Login

Welcome to the Technology Advisors Blog!!

A short description about your blog
Jul 26
2011

How to pull data from a sub-grid on a parent form in MSCRM

Posted by: Administrator in MyBlog

Administrator

In Microsoft Dynamics CRM 2011 it is possible to pull data from a sub-grid on a parent form when a page loads to read the values.

Place the script below inside a Web Resource and call the function "calcPortfolio" on a "OnLoad" event

function calcPortfolio()
{
                var portAmount = 0.00;
                //name of the sub-grid
                var gridControl = document.getElementById("SubGridName").control;                 var ids = gridControl.get_allRecordIds();                 for(i = 0; i < ids.length; i++)                 {                                               var cellValue = gridControl.getCellValue('SubGridField', ids[i]);                                 // cellValue has a datatype of Currency
                                cellValue = parseFloat(cellValue.replace(/[$,]+/g,""));                                 portAmount = portAmount + cellValue;
               }                 var Name = Xrm.Page.data.entity.attributes.get("fieldOnParentForm");
                Name.setValue(portAmount);

}

Apr 13
2011

Adding a Multi-Select Picklist to Microsoft Dynamics CRM 2011

Posted by: Administrator in MyBlog

Administrator

Microsoft Dynamics CRM 2011 doesn't have multi-select picklist controls available. The standard CRM picklist can only save one value in the database and it is not easy to extend this functionality. In addition, you have to deal with the Advanced Find Feature.

Original code came from Jim Wang (http://blogs.msdn.com/b/crm/archive/2009/03/31/crm-4-0-checkbox-style-multi-select-picklist.aspx)
 but needed customization to work for MCRM 2011

Changes to original code:
    1.  I added an "onClick()" event to build the string of values each time a checkbox is checked.      2. The original code did not save it's values into the database when the "Save" button was clicked, so I added 2 additional lines of          code to Set the values in the textbox and allow MCRM to save the data.

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

Microsoft Dynamics CRM

The script below will draw a checkbox style multi-select picklist control on the CRM form, and then get options from the real picklist attribute.
1.  Controls - Create a picklist and populate it with values & a textbox to store the string of values selected from the picklist
2.  Put the picklist on the form where you want the new Multi Select Picklist to show up
3.  Create a web Resource:
     Go to  "Settings", "Customization", "Customize the System". Click "Web Resource" and then "New"
    Type in the name of the Web Resource, Display Name...
    Select "Script (JScript)" and choose the Language.      Click the Text Editor button and paste the code below to the source area on the form.
                Click "OK" then "Save and Close"

Microsoft Dynamics CRM

4.  Add the event to the form:
    Go to  "Settings", "Customization", "Customize the System". Expand "Entity" then expand "Account" and click "Forms"
    Select the form where you added the picklist and textbox.  And click "Form Properties" button      Add the new Web Resource to the Library by clicking the "Add" button, then select the new web Resource and click "OK"
    In the Event Handlers section click "Add", select the Library file and enter the Function name (In our example: "AccountOnLoad") and click "OK" and "OK"     again
5.  Save and Publish All Customizations


Here is the Sample code - You'll need to change the values in RED

 

function AccountOnLoad ()

{

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

var PL = crmForm.all.new_areaaccess;     //CREATE NEW PICKLIST

var PLV = crmForm.all.new_areaaccesstext;  //CREATE NEW TEXT FIELD TO STORE STRING

 

PL.style.display = "none";       //HIDES THE CONTROL

PLV.style.display = "none";     //HIDES THE CONTROL

 

    // Create a DIV container    

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

    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' onclick='CallOnChangeEvent()' style='border:none; width:25px; align:left;' />" );

        else    

        var addInput = document.createElement("<input type='checkbox' onclick='CallOnChangeEvent()' checked='checked' style='border:none; width:25px; align:left;' />" );

        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.value != "")

      {

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

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

      {

         if( PLVT[i] == pText )

         return true;

      }

    }

    return false;

   }

}

 

function CallOnChangeEvent()

{

      var PL = crmForm.all.new_areaaccess;  

      var PLV = crmForm.all.new_areaaccesstext;

      PLV.value = "";

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

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

      {

         if( getInput[i].checked)

         {

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

         }

      }

 

     //MUST DO THIS TO TRIGGER A SAVE EVENT

     var Name = Xrm.Page.data.entity.attributes.get("new_areaaccesstext");

    Name.setValue(PLV.value);

}