Pages

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");

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

2 comments:

  1. Hi,

    I have a regarding object lookup, how to get the list of all entities listed in the lookup using javascript in 2015? Kindly help

    ReplyDelete