Friday 3 April 2015

Customize PartyList in CRM 2013 and 2015

We used to customize partylist in CRM 2011 by using the following code.

lookuptypeIcons = '/_imgs/ico_16_2.gif:/_imgs/ico_16_8.gif';
lookuptypenames = 'contact:2:Contact,systemuser:8:User';
lookuptypes = '2,8';
if (crmForm.all.to != null) {
       crmForm.all.to.setAttribute("defaulttype", "2");
       crmForm.all.to.setAttribute("lookuptypes", lookuptypes);
       crmForm.all.to.setAttribute("lookuptypenames", lookuptypenames);
       crmForm.all.to.setAttribute("lookuptypeIcons", lookuptypeIcons);
       Xrm.Page.getControl("to").setDefaultView("A2D479C5-53E3-4C69-ADDD-802327E67A0D"); //GUId for  default View 
}

This code won't work in CRM 2013 and 2015 but we can achieve same functionality by write the code on the focus of the field


$("#to").focus(function () {
    var toLookUp = $("img[attrName='to']");
    var lookuptypeIcons = '/_imgs/ico_16_2.gif?ver=828891367:/_imgs/ico_16_8.gif??ver=828891367';
  var lookuptypenames = 'contact:2:Contact,systemuser:8:User';
    lookuptypes = '2,8';
    if (toLookUp.length > 0) {
        toLookUp[0].setAttribute("lookuptypenames", "contact:2:Individual,systemuser:8:User");
        toLookUp[0].setAttribute("lookuptypes", "2,8");
        toLookUp[0].setAttribute("lookuptypeIcons", lookuptypeIcons);
        toLookUp[0].setAttribute("createpermissiondictionary", "contact:true,systemuser:true");
        toLookUp[0].setAttribute("DefaultViewId", "A2D479C5-53E3-4C69-ADDD-802327E67A0D");
        toLookUp[0].setAttribute("defaulttype", 2);
    }
});


--
Happy CRM'img
Gopinath

5 comments:

  1. Hi....
    I wrote this code

    function Test()
    {
    alert("hello");
    $("#to").focus(function () {
    var theLookupTO = $("img[attrName='to']");
    alert(theLookupTO);
    if(theLookupTO.length > 0)
    {

    theLookupTO[0].setAttribute("lookuptypenames", "systemuser:8:User");

    theLookupTO[0].setAttribute("lookuptypes", "8");

    theLookupTO[0].setAttribute("lookuptyprIcons", "/_img/ico_16_8.gif?ver=828891367");

    theLookupTO[0].setAttribute("createpermissiondictionary", "systemuser:true");

    theLookupTO[0].setAttribute("DefaultViewID", "{A2D479C5-53E3-4C69-ADDD-802327E67A0D}");

    theLookupTO[0].setAttribute("defaulttype","8");

    }

    });

    }

    and then called the function Test.But it did not work. can you please help if anything else to be done to write a jQuery

    ReplyDelete
  2. Hi Gopinath,

    i tried to use your code , but couldnt achieve it.

    can help ??

    ReplyDelete
  3. Hi gopi,

    i tried the same but couldnt achieve this. do we need to add any jquery reference for this??

    ReplyDelete