Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Retrieve Data from N:N Relation ship using Java script

Posted on by 155

Hi,

Marketing List and contact has n:n relation.When I am adding contacts in contact sub grid from marketing list, need to retrieve contacts and marketing list data using java script.

*This post is locked for comments

  • gdas Profile Picture
    gdas 50,085 on at
    RE: Retrieve Data from N:N Relation ship using Java script

    Hi Neethu ,

    Thanks for your clarification , now I understood your requirement .

    I believe you know that without relationship you can not show any subgrid and this is how relationship works.

    If my understanding is correct you are going to display those campaign in the contact form which the marketing list (contacts) associate with particular campaign.

    You cant do this  OOB  without any relationship , you may think some alternate way or go for custom html retrieving  the campaign data and display in third party grid.

    The filter would be get the marketing list id of particular contact  in one query and then using marketing list id's you can retrieve associated campaign data .

  • Neethu Sara Thomas Profile Picture
    Neethu Sara Thomas 155 on at
    RE: Retrieve Data from N:N Relation ship using Java script

    Hello Goutam,

    Thanks for your quick response. I will attach screen shot about my requirement.

    Marketing-List-2.png

    This is Campaigns entity form view,red circled is marketing list grid view.Campaign to marketing list entity has n:n relationship.

    Marketing-List-2.png

    This is Marketing list form view. first red circled is contact grid view(member). Marketing list to contact also have n:n relationship.second red circled has showing campaigns grid view linked with that particular marketing list.The same campaign grid view list need to show in contact entity what are the contacts linked with the particular marketing list.Now i don't have any direct relationship between campaigns and contact. 

  • gdas Profile Picture
    gdas 50,085 on at
    RE: Retrieve Data from N:N Relation ship using Java script

    Hello Neethu ,

    Based on your earlier question you want to retrieve the  marketing list contact information using Javascript , so call web API using Javascript which I have shared and it will work for all instance of dynamics 365 online or on-premise.

    I am not very clear about your requirement - "When I Select Contacts in member named grid, I want to show Campaigns grid views in selected contact entity." Could you please give some more details on it so that may be I can help you.

  • Neethu Sara Thomas Profile Picture
    Neethu Sara Thomas 155 on at
    RE: Retrieve Data from N:N Relation ship using Java script

    Hi Goutam,

    I am working with dynamics 365 online. I don't want to call webapi because working inside dynamics 365 only.Actually my requirement is,

    Campaigns have marketing list. This marketing list has one field called 'Targeted At'. If i am selecting a contact entity in 'Targeted At' field i can create a contact in member grid view. When I Select Contacts in member named grid, I want to show Campaigns grid views in selected contact entity. Campaign to marketing list has n:n relation and marketing list to contact also n:n relationship.Need to display parent in grandchildren entity sub grid.Any possible way to customise and achieve this?  

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Retrieve Data from N:N Relation ship using Java script

    Hi Neethu ,

    I would request download the CRMRestBuilder . In CRMRestBuilder select the entity called "list" and then in Many to Many select your contact association field and  in addition you can provide filter.

    https://github.com/jlattimer/CRMRESTBuilder

    Here is sample I have prepared have a look -

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/lists?$select=description,listid,listname&$expand=listcontact_association($select=fullname,jobtitle,lastname)", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                for (var i = 0; i < results.value.length; i++) {
                    var description = results.value[i]["description"];
                    var listid = results.value[i]["listid"];
                    var listname = results.value[i]["listname"];
                    //Use @odata.nextLink to query resulting related records
                    var listcontact_association_NextLink = results.value[i]["listcontact_association@odata.nextLink"];
                }
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();


    mktlst1.png

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans