Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Query and Layout

Posted on by 2,215

Hi, I have a custom lookup field (connects with Contacts) in the Account's form. I want to get all contacts in the lookup view which parentcustomerid coincides with the account's name. Here is my code:

 

//////////////////////////////////////////////

function a1() {

    var account_name = Xrm.Page.getAttribute("name").getValue();

 

 

 

        var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; //Random GUID

        var entityName = "contact";

        var viewDisplayName = "custom view for contacts";

 

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

                                        "<entity name='contact'>" +

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

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

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

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

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

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

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

                                                "<filter type='and'>" +

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

       // "<condition attribute='fullname' operator='like' value='Abc%' />" +

 

                                      "</filter>" +

                                        "</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='300' />" +

                    "<cell name='parentcustomerid' width='300' />" +

                                                "<cell name='telephone1' width='150' />" +

                                                "<cell name='emailaddress1' width='100' />" +

                    "<cell name='jobtitle' width='100' />" +

                                        "</row>" +

                                      "</grid>";

 

        Xrm.Page.getControl("new_head").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

 

    }

 Please help me to understand why it does not work.

Thanks in advance

 

*This post is locked for comments

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans