Dynamics 365





Wednesday, September 11, 2013

SubGrid Refresh or SubGrid Attach even usig Java Script

 below peice of code to refresh the subgrid.
 
function SubGridLoadWait() {
    setTimeout(OnAccountFormLoad, 3000);
}

function OnAccountFormLoad() {
    //Set Action on subgrid Refresh
    //debugger;
    var subGrid = document.getElementById("SuspectGrid");
    //if(subGrid) {
    subGrid.attachEvent("onrefresh", getPrimaryRows);

    //SubGrid.attachEvent("onrefresh", CallbackFunction);
    //SubGrid.control.add_onRefresh(CallbackFunction);

    //}

}

//This function fires on subgrid refresh

function getPrimaryRows() {
    var isPrimaryYes = false;
    var isPrimaryNo = false;
    var gridControl = document.getElementById('SuspectGrid').control;
    var ids = gridControl.get_allRecordIds();
    for (i = 0; i < ids.length; i++) {

        var primary = gridControl.getCellValue('new_isprimarysuspect', ids[i]);
        if (primary=="Yes") {
            isPrimaryYes = true;
            break;
        }
        else if(primary=="No"){
            isPrimaryNo = true;
        }
    }
    if (isPrimaryYes) {

        Xrm.Page.getAttribute("new_canhaveprimarysuspect").setValue(true);
//        alert("Primary Suspect checked");
    }
    else if (isPrimaryNo) {
        Xrm.Page.getAttribute("new_canhaveprimarysuspect").setValue(false);
      //  alert("Primary Suspect unchecked");
    }
}

Tuesday, September 3, 2013

Capitalize First String Character of a word in Text Field of Dynamics CRM 2011

 Capitalize First String Character of a word in Text Field of Dynamics CRM 2011
So, One of the Post in LinkedIn asking if anyone can help with a Script that can Capitalize First String Character of a word in Text Field of Dynamics CRM 2011.

For eg. If i have a custom Full Name Field or Address filed. If User enters like 1107 medowville lane,
The script should automatically converts it to Pascal Casing like, 1107 Medowville Lane.

I thought to give it a try and here is the full functional code.

function ConvertFirstCharToCaps()
{
var attribute = Xrm.Page.getAttribute("new_address"); // Change the Schema Name here

if(attribute != null)

var str = attribute.getValue();
    var pieces = str.split(" ");
    for ( var i = 0; i < pieces.length; i++ )
    {
        var j = pieces[i].charAt(0).toUpperCase();
        pieces[i] = j + pieces[i].substr(1);
    }

Xrm.Page.getAttribute("new_address").setValue(pieces.join(' '));

}

It can be converted to Parametrized Function, but here i am just giving an idea how this code can work on each field.

Hope this will help, Please change the Attribute name as per your Attribute Schema Name.

Thanks.