Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Web API query

Posted on by Microsoft Employee

Hello,

I'm facing a problem to add members in team, the structure of my collection doesn't pass, any help please? here is my code generated by CRM BUILDER

var parameters = {};
parameters.Members = "Collection(mscrm.systemuser) Not Handled";

var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/teams(740D4C8E-9FFC-E632-84FA-5055F49AEA41)/Microsoft.Dynamics.CRM.AddMembersTeam", false);
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.onreadystatechange = function() {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 204) {
            //Success - No Return Data - Do Something
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send(JSON.stringify(parameters));


Thank you

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Web API query

    Hi, 

    Thank you for the response, i'm getting Can't add members to the default business unit team. The query doesn't work with default teams? Thanks

  • MattB-MSFT Profile Picture
    MattB-MSFT on at
    RE: Web API query

    No issues,  Staring at GUIDS long enough and they all blend together.  Happy it was a simple thing.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Web API query

    Matt,

    Thanks. That was a stupid mistake. Now it works fine.

  • MattB-MSFT Profile Picture
    MattB-MSFT on at
    RE: Web API query

    So looking at your example:

    POST [Organization URI]/api/data/v8.2/teams(2AF3F0D3-A30F-E711-810A-3863BB34FB48)/Microsoft.Dynamics.CRM.AddMembersTeam HTTP/1.1

    The ID of the team is : 2AF3F0D3-A30F-E711-810A-3863BB34FB48

    In your data your passing in, your passing in the SAME ID for the system user:  Members: [{"ownerid": "2af3f0d3-a30f-e711-810a-3863bb34fb48"}] 
    In this case, your trying to tell it to add a itself(the team) to the team,  thus a circular ref.  thus the SQL error.

    if you use a system user vs a the team itself, it will work.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Web API query

    Matt,

    I tried that approach and I keep getting "Generic SQL Error". Here is my request:

    POST [Organization URI]/api/data/v8.2/teams(2AF3F0D3-A30F-E711-810A-3863BB34FB48)/Microsoft.Dynamics.CRM.AddMembersTeam HTTP/1.1

    Accept: application/json

    Content-Type: application/json; charset=utf-8

    OData-MaxVersion: 4.0

    OData-Version: 4.0

    {

    Members: [{"ownerid": "2af3f0d3-a30f-e711-810a-3863bb34fb48"}]

    }

  • Suggested answer
    MattB-MSFT Profile Picture
    MattB-MSFT on at
    RE: Web API query

    The syntax your going for is this:

    where the TeamID = 37C0E3C9-7A0F-E711-810E-C4346BB59828

    where the userID being added is = f8585131-320f-4503-91e9-46a3791baae4

    The URI would look like this :

    (rootURL)/api/data/v8.2/teams(37C0E3C9-7A0F-E711-810E-C4346BB59828)/Microsoft.Dynamics.CRM.AddMembersTeam

    The body would contain

    {

     "Members": [{ "ownerid":"f8585131-320f-4503-91e9-46a3791baae4"}]

    }

    When executed and successful you will get a 204 No content back on success.

    if you needed more then one user, you would add ownerid: ID array elements to it.

    Hope that helps.

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