web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Is there a supported way via JS to filter Party Lists?

(0) ShareShare
ReportReport
Posted on by

In our organization we want the Email entity's "To" party list to be limited to just one custom entity which will basically act like our internal address book in Outlook.  I've searched all over the internet and read several pieces of example code, but I don't see a supported way to do this.  The best solution I've seen is in https://community.dynamics.com/crm/f/117/t/128748, but it is using the unsupported method document.getElementById().

Another option I came across is http://stackoverflow.com/questions/29256667/lookup-contacts-instead-of-accounts-on-emails-in-ms-dynamics-crm-2013 but to use this I would need to hard-code the GUID for a View of our custom entity.  To get around hard-coding, I could query the database for a specific view name and if it doesn't exist, NOT change the view, but this is a less than ideal method that I'd rather avoid.

I'm hoping someone can point me to a support method.

Instead of document.getElementById("to_i").setAttribute("defaulttype", "8"), could Xrm.Page.getControl("to_i").getAttribute("defaulttype").setValue("8") work instead?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    KG_CRM Profile Picture
    on at

    I tested Xrm.Page.getControl("to_i").getAttribute("defaulttype").setValue("8") and as far as I could tell it doesn't work.

    I spent some more times searching the internet for potential solutions and found two blog posts with some more possibilities:

    https://lakshmanindian.wordpress.com/2012/10/23/filter-partylist-entities-lookup-using-jscript-in-microsoft-dynamics-crm-2011/

    https://ashishkhanna.wordpress.com/2014/07/09/limit-customer-lookup-to-show-only-accounts-or-contacts/

    In Lakshman's blog he mentions the document.getElementById() method and a crmForm.all.to.setAttribute("defaulttype") method which I read online is also unsupported.  However he did mention one additional method using Jquery and Json2 but I do not know if this method is supported by MS or not.

    In Ashish's blog, I'm fairly certain his code is supported, however it's not perfect as the 'Lookup More Records' still shows the entitiy types who's records are all hidden.  Also, to adapt it to my needs requires a 'for loop'.  Below is what I came up with to hide all of the OOB entities available in the To field when I was logged in as a system admin.  I have not fully tested the code below, but a I did have a previous version of this working so I hope that this works as well.

    function EmailLookupFilters() {
        Xrm.Page.getControl("to").addPreSearch(function() {
            EmailFilter("to");
        });
        Xrm.Page.getControl("cc").addPreSearch(function() {
            EmailFilter("cc")
        });
        Xrm.Page.getControl("bcc").addPreSearch(function() {
            EmailFilter("bcc");
        });
    }
    
    // Hide all of the OOB entity records from the given PartyList field.
    function EmailFilter(fieldname) {
        var HideEntities = ["account", "contact","entitlement", "equipment", "lead", "queue", "systemuser"];
        var filter;
        var i;
        for (i = 0; i<HideEntities.length; i++) {
            filter = 
                "<filter type='and'>" +
                    "<condition attribute='" + HideEntities[i] + "id' operator='null' />" +
                "</filter>";
            Xrm.Page.getControl(fieldname).addCustomFilter(filter, HideEntities[i]);
        }
    }
  • Community Member Profile Picture
    on at

    Hi KG_CRM,

    I have tested this and it doesnt solve the main issue : which is setting a certain entity as default in the case of a customer or partylist fields. What it does is filter of the result set. 

    The only solution which I have found for the moment is un-supported. 

    Cheers

  • KG_CRM Profile Picture
    on at

    Hi Corina,

    The code I listed above is working well enough for our needs, although I am no longer using a custom entity for address book.  I'll explain that in detail below.  What the code I posted helps with is when typing directly in the To, CC, and BCC field and hitting enter to  search, the results shown there are only Entities that haven't been hidden.  If you do open the 'Look Up More Records' it still defaults to the Account entity and shows all of the entities in 'Look For' but searching here for those entities will still return nothing.  This isn't a big issue as we do not have a lot of contacts with the same name that we need to go into the 'Look Up More Records' to find the correct one.

    There is one caveat to this.  This filtering only works when searching by First Name, Last Name, Full Name etc. and not email address.  If you search the To, CC, and BCC fields for an email address the results will still include all entities that use that email, which is a useful exception.  Most of our users search by Last Name or Full Name so this works just fine for us.

    The issue we had when using a custom entity as our internal address book was when we received an email from those Contacts, CRM was sometimes creating a Contact record for that Contact instead of linking to the custom entity.  This resulted in multiple CRM records with the same email address.  Then when replying to those emails, CRM will include a link to every entity with that email address into the To field so the same person would be listed multiple times; as a Contact and again as the custom entity.  What I've done instead is add a custom boolean field to Contacts to indicate if it's an internal contact vs. an external contact and filtering based on that field.  In our system I named that field "Show in Address Book" since some of the results we want to show are not internal.

  • Verified answer
    BharatPremji Profile Picture
    2,485 on at

    Hi,

    This might be a bit of a hack but could you add a new lookup field on your Email entity which points to the custom entity?  You could then use Javascript to copy the value from this new field to the 'To' field.

    Bharat

  • Verified answer
    Brad Sprigg Profile Picture
    985 on at

    Hi there

    I've used the below code to filter the From field on the Phone Call entity before, it isn't perfect because they can still select one of the other entities, but they get no results. Each time you use addCustomFilter it adds another filter as an "AND" so you repeat the process for each entity you want to disallow.

    preFilterLookup = function() {    
    
    Xrm.Page.getControl("from").addPreSearch(function () {
    
        addLookupFilter();
    
      });
    
    }
    
    addLookupFilter = function() {
    
     fetchXml = "<filter type='and'><condition attribute='name' operator='eq' uitype='account' value='slkjdghkshgbkej' /></filter>"
    
     Xrm.Page.getControl("from").addCustomFilter(fetchXml, "account");
    
    }
    function phonecall_onLoad() {
    preFilterLookup();  
    }


  • Community Member Profile Picture
    on at

    Ok, glad the filtering functionality provided by the supported methods, is enough for your requirements.

    Hopefully, we will get soon an OOB set default type method for multi-lookups in future CRM releases/updates.

    /cheers

  • KG_CRM Profile Picture
    on at

    @ Bharat, this is an interesting idea I hadn't thought of before, but if that custom field is now visible while the party list field is hidden, users can only send emails to those entities.  For my company's use case, we still need to send emails to multiple entity types.

    Perhaps this would work for CorinaB?

  • KG_CRM Profile Picture
    on at

    @Brad, while the arrangement is different this is basically the same code method that I posted above.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans