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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

add Custom view

(0) ShareShare
ReportReport
Posted on by 3,674

dear all,

i have this scenario:

i have list of volunteers(contact entity), and someone will make a volunteer request(custom entity) according to some conditions, after that i use plugin to have list of volunteers that matching requested skills and copy them to third entity called volunteer request selected (custom entity) this entity have volunteers Id, volunteer request Id and it's own id.

my problem is when i in another entity and have  a lookup to volunteers(contact entity) called "new_volunteer", but i need to load all volunteers with specific volunteer request Id. i suppose that i have volunteer request Id ( i get it using window.top.opener.Xrm.Page.data.entity.getId().

i know that i have to use addcustomview.

is this code javascript below true (cause i have an error):

i need for sample load all volunteers in request2 (req2)

function preFilterLookupVolunteer()
 {   
 Xrm.Page.getControl("new_volunteer").addPreSearch(function () {  addLookupFilterVolunteer();  });
}

function addLookupFilterVolunteer()
 {
\\get the request id.
var reqid= window.top.opener.Xrm.Page.data.entity.getId();
alert(reqid);

 var viewId = "{44B23EF1-0ADD-E411-817C-00155DEE9E05}"; //view Guid  
  var entityName = "contact";  
var viewDisplayName = "volunteerinReq"; // my custom view 

    var  fetchXml ="<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
  <entity name="contact">
    <attribute name="fullname" />
    <attribute name="contactid" />
    <order attribute="fullname" descending="false" />
    <link-entity name="new_volunteer_requestselected" from="new_volunteer" to="contactid" alias="aa">
      <filter type="and">
        <condition attribute="new_volunteerrequestedid" operator="eq" uiname="req2" uitype="new_volunteersrequest" value="{B7EAC8CE-6CD0-E411-816F-00155DEE9E05}" />
      </filter>
    </link-entity>
  </entity>
</fetch>";

 var layoutXml = "<grid name='resultset' " +                    
"object='1' " +  
"jump='name' " +                    
"select='1' " +                    
"icon='1' " +                   
 "preview='1'>" +                   
 "<row name='result' " +                   
 "id='contactid'>" +
 "<cell name='fullname' width='250' />" +                   
 "</row>" +                    
"</grid>";

   Xrm.Page.getControl(“new_volunteer”).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

}

thanks all in advance.


*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: add Custom view

    Hi,

    Please show the error?

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: add Custom view

    What's the error now Hamzeh?

  • Hamzeh Zawahreh Profile Picture
    3,674 on at
    RE: add Custom view

    yes aileen, i used advanced find to build it and it's returned result when i run it,

    but when i copy it to js function and add it to form load event it's have and error.

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: add Custom view

    Hi Hamzeh,

    Have you tried to build the XML using the advanced find?

    It would help you so much.

    Thanks.

  • Hamzeh Zawahreh Profile Picture
    3,674 on at
    RE: add Custom view

    not worked with my case, i want to know if my addCustomView is valid as my example.

    aileen i remove the preSearch and it's still not worked :(

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: add Custom view

    Hamzeh,

    For the linked entity (Parent)

    You can use this method:

    missdynamicscrm.blogspot.sg/.../crm-2013-using-addcustomfilter-to-get-filtered-lookup-field-based-on-linked-entity.html

    Thanks,

  • Hamzeh Zawahreh Profile Picture
    3,674 on at
    RE: add Custom view

    dear Mahadeo Matre

    the addCustomFilter will not work with linkentity

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: add Custom view

    check this code..

    function addEventHandler() {

       // add the event handler for PreSearch Event

       Xrm.Page.getControl("parentcustomerid").addPreSearch(addFilter);

    }

    function addFilter() {

       //check if the city is not empty

       if (Xrm.Page.getAttribute("address1_city").getValue() != null) {

           var city = Xrm.Page.getAttribute("address1_city").getValue();

           //create a filter xml

           var filter ="" +

                        "" +

                        "";

           //add filter

           Xrm.Page.getControl("parentcustomerid").addCustomFilter(filter);

       }

    }

    More details are here

    https://community.dynamics.com/crm/b/mscrmshop/archive/2013/10/24/addcustomfilter-method-for-lookup-control-in-crm2013.aspx

    might be helpful..

  • Hamzeh Zawahreh Profile Picture
    3,674 on at
    RE: add Custom view

    hi aileen here is the contact view (volunteer)

    2148.2.png

    and here the fetchxml

    6646.3.png

    and here is the selected entity custom entity

    6787.4.png

    and here where i am need to filter lookup using fetchxml and link entity using addCustomview

  • Aileen Gusni Profile Picture
    44,524 on at
    RE: add Custom view

    Hi Hamzeh,

    What error you got?

    i am not sure your current design, can help to elaborate more by screenshot?

    Btw if you use this method: addCustomView(params)

    You dont need to have this addPreSearch function

    Xrm.Page.getControl("new_volunteer").addPreSearch(function () {  addLookupFilterVolunteer();  });

    You only need to call the real function: 'addLookupFilterVolunteer'

    Thanks,

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans