Pages

Tuesday 22 April 2014

Retrieve SubGrid Records MS CRM 2013 using JavaScript

function RetrieveSubGridRecords() {
    if (document.getElementById("Sub Grid Name")) {
        var grid = document.getElementById("Sub Grid Name").control;
        for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++)
            for (var cellNo = 0; cellNo < grid.GetRecordsFromInnerGrid()[rowNo][3].cells.length; cellNo++)
                alert(grid.GetRecordsFromInnerGrid()[rowNo][3].cells[cellNo].outerText);    }    else {
        setTimeout("RetrieveSubGridRecords();", 2500);
    }}


Hope it Helps

Wednesday 2 April 2014

Restrict Partylist Lookup of Phone Entity only to Contacts in CRM 2013

Hi,
In CRM 2013, by default the when we open a form it looks different, so when we hover mouse over the attribute then we can get to know whether it is Lookup or normal field.
Since in the above figure Regarding,Call to are Lookup fields so once we hover the mouse over it then we can understand it.

now in "Regarding" field I have to select "Account" records, once I select Account record in "Regarding" attribute. The "Call to" attribute should be filtered to corresponding Contacts.

So in my code I am Initiating my page, so that i can get the lookup fields,
the Snippet is given below,
------------------------->
function setfilterforlookup(econtext)
{
debugger;
var test=Xrm.Page.getControl("to");  //this line is to initiate my form

test.addPreSearch(addFilter);

document.getElementById("to_i").setAttribute("defaulttype","2");  //to_i is id name of my  lookup in crm 2013 which we can get from debugging page, from HTML format go to the desired lookup
document.getElementById("to_i").setAttribute("lookuptypes","2");
document.getElementById("to_i").setAttribute("lookuptypenames","contact:2:Contact");

}


function addFilter() {
    //check if the city is not empty
    
var lookupObject = Xrm.Page.getAttribute("regardingobjectid").getValue();
var id = lookupObject[0].id;
        //create a filter xml
        var filter ="<filter type='and'>" +
                     "<condition attribute='parentcustomerid' operator='eq' value='" + id + "'/>" +
                     "</filter>";
        //add filter
        Xrm.Page.getControl("to").addCustomFilter(filter,"contact");

    }
-------------------------->