locked
Filtering contracts on opportunity RRS feed

  • Question

  • Hi,

    I have added one contact lookup field as Contact Person on opportunity.  But it display all the contacts of all the accounts on lookup.  I want to display the contacts of selected account only in the contact lookup.  Is there any way we can filter this lookup.

    I have selected related filtering but it does not work.

    Please find screen-shot for your reference and help to solve this issue.


    pnoushu@hotmail.com

    Sunday, September 13, 2015 1:31 PM

All replies

  • Monday, September 14, 2015 7:06 AM
    Moderator
  • // FUNCTION: setLookup


    function

    setLookup() {

       

     var defaultViewId = Xrm.Page.getControl(

    "ymf_ownerpersonid").getDefaultView();

    // Get the selected Account Id in the [accountFieldName] indicated control


       

    varteam = Xrm.Page.getAttribute("ymf_owningteamid").getValue();

       

    if(team != null) {

           

    varteamid = team[0].id;

           

    varteamname = team[0].name;

           

           

    // use randomly generated GUID Id for our new view


           

    varviewId = "{ad886ecf-d3e9-44f8-b9dd-3164d5d8b40d}";

           

    varentityName = "systemuser";

           

    // give the custom view a name


           

    varviewDisplayName = "Active Users for "+ teamname + "";

           

    // find all contacts where [Parent Customer] = [Account indicated by AccountId]


           

    // AND where [Statecode] = Active


           

    varfetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+

                          

    "<entity name='systemuser'>"+

                               

    "<attribute name='fullname' />"+

                               

    "<attribute name='businessunitid' />"+

                               

    "<attribute name='title' />"+

                               

    "<attribute name='address1_telephone1' />"+

                               

    "<attribute name='systemuserid' />"+

                               

    "<order attribute='fullname' descending='false' />"+

                               

    "<link-entity name='teammembership' from='systemuserid' to='systemuserid'>"+

                                   

    "<link-entity name='team' from='teamid' to='teamid'>"+

                                       

    "<attribute name='name' />"+

                                       

    "<filter type='and'>"+

                                           

    "<condition attribute='teamid' operator='eq' value='"+ teamid + "' />"+

                                       

    "</filter>"+

                                    

    "</link-entity>"+

                               

    "</link-entity>"+

                           

    "</entity>"+

                           

    "</fetch>";

           

    // build Grid Layout


           

    varlayoutXml = "<grid name='resultset' "+

                                    

    "object='1' "+

                                    

    "jump='systemuserid' "+

                                    

    "select='1' "+

                                    

    "icon='1' "+

                                    

    "preview='1'>"+

                                

    "<row name='result' "+

                                     

    "id='systemuserid'>"+

                                  

    "<cell name='fullname' "+

                                        

    "width='200' />"+

                                  

    "<cell name='businessunitid' "+

                                        

    "width='250' />"+

                                  

    "<cell name='title' "+

                                        

    "width='250' />"+

                                   

    "<cell name='address1_telephone1' "+

                                        

    "width='250' />"+

                                

    "</row>"+

                              

    "</grid>";

           

    // add the Custom View to the indicated [lookupFieldName] Control


            Xrm.Page.getControl(

    "ymf_ownerpersonid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

        }

       

    else{

           

    // no Account selected, reset Contact Lookup View to the default view such that all Contacts are displayed for selection


            Xrm.Page.getControl(

    "ymf_ownerpersonid").setDefaultView(defaultViewId);

        }

    }


    Hope this helps. ----------------------------------------------------------------------- Santosh Bhagat If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful"

    Tuesday, September 15, 2015 10:02 AM
  • Hi,

    Please help me,  to understand how Related Records filtering working.  I need to display in lookup only the contact of the account which I selected as potential customer. For example   John  contact of  account ABC,  Roshan  contact of  account ABC, Shan contact of account DEF.  I selected ABC as potential customer or account in opportunity.  I added a new lookup field as contacts in opportunity so I want to display only John and Roshan in contacts lookup.  No need to display all contacts.

    Regards,

    Noushad


    pnoushu@hotmail.com

    Tuesday, October 6, 2015 3:34 PM
  • Hello,

    This could be done without any coding. Recheck please following article - http://garethtuckercrm.com/2011/03/22/filtered-lookup-approaches-in-crm-2011/


    Dynamics CRM MVP
    My blog

    Tuesday, October 6, 2015 3:45 PM
    Moderator