Filter PartyList entities Lookup using Jscript in Microsoft Dynamics CRM 2011

Posted: October 23, 2012 in CRM 2011, Jscripts

In the Phone Call entity there is a field called “Recipent” which is a datatype of PartyList. And by default it shows Account, Contact, Lead and User entities.

If you want to show only “Contacts” in the lookup, then you can add the following jscript code in your phone call entity “onload” event.

function OnLoad() {
    document.getElementById("to").setAttribute("defaulttype", "2");
    document.getElementById("to").setAttribute("lookuptypes", "2");
    document.getElementById("to").setAttribute("lookuptypeIcons", "/_imgs/ico_16_2.gif");
}

You can also achieve the same by using “crmForm.all” instead of “document.getElementById”

function OnLoad() {
    crmForm.all.to.setAttribute("defaulttype", "2");
    crmForm.all.to.setAttribute("lookuptypes", "2");
    crmForm.all.to.setAttribute("lookuptypeIcons", "/_imgs/ico_16_2.gif");
}

If you want to achieve using Jquery, then you can add the following code. Dont forget to add jquery1.4.1.min and json2 files in your Form Properties. You can get those files from sdk.
path – \sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts.

function OnLoad() {
    $("#to").attr("defaulttype", "2");
    $("#to").attr("lookuptypes", "2");
    $("#to").attr("lookuptypeIcons", "/_imgs/ico_16_2.gif");
}

Filter 2 entities in the Recipent lookup

Now for example if you want to filter 2 entities in the Recipent lookup, you can add the following code on your onload event. Im using Account and Contact in my example.

function OnLoad() {
    document.getElementById("to").setAttribute("lookuptypenames", "contact:2:Contact,account:1:Account");
    document.getElementById("to").setAttribute("lookuptypes", "1,2");
    document.getElementById("to").setAttribute("lookuptypeIcons", "/_imgs/ico_16_2.gif:/_imgs/ico_16_1.gif");
}

You can also achieve the same by using “crmForm.all” instead of “document.getElementById”

function OnLoad() {
    crmForm.all.to.setAttribute("lookuptypenames", "contact:2:Contact,account:1:Account");
    crmForm.all.to.setAttribute("lookuptypes", "1,2");
    crmForm.all.to.setAttribute("lookuptypeIcons", "/_imgs/ico_16_2.gif:/_imgs/ico_16_1.gif");
}

If you want to achieve using Jquery, then you can add the following code. Dont forget to add jquery1.4.1.min and json2 files in your Form Properties. You can get those files from sdk.
path – \sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts.

function OnLoad() {
    $("#to").attr("lookuptypenames", "contact:2:Contact,account:1:Account");
    $("#to").attr("lookuptypes", "1,2");
    $("#to").attr("lookuptypeIcons", "/_imgs/ico_16_2.gif:/_imgs/ico_16_1.gif");
}
Advertisements
Comments
  1. Michelle says:

    nice info, but i want to ask something. can we also filtering the data on each entity? can we set the default lookup view or do some script to addcustomview?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s