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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Web API error when inserting values for N:N relationship

(0) ShareShare
ReportReport
Posted on by 2

I am trying to add users to a team using Web API but was thrown with below error. 

I tried reversing entities as mentioned in other posts but of no avail. Same error pops up. 

5_2D00_30_2D00_2018-4_2D00_43_2D00_27-PM.jpg

Please see my code below. Any help is very much appreciated. Also , please let me know why this error pops up.

for (var j = 0; j < teamids.length; j++) {
var AssociationParameter = {"@odata.id": "crmurl/.../teams(" + teamids[j] + ")"};
var url = "crmurl/.../systemusers(" + id + ")/" + AssociationName + "/$ref";
var req = new XMLHttpRequest();
req.open("POST", url, false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;

if (this.status === 204 || this.status === 1223) {
alert("role associated - roleid");
}
else {
alert(JSON.parse(this.response).error.message);
}
}

}
};
req.send(JSON.stringify(AssociationParameter));
}

*This post is locked for comments

I have the same question (0)
  • Kevin Grech Profile Picture
    380 on at

    AssociationParameter value should be enclosed in square brackets to indicate an array (ObjectCollection equivalent). I don't have good code handy but I think it should be something like this:

    var AssociationParameter = {[{"@odata.id": "crmurl/.../teams(" + teamids[j] + ")"}]};

  • Goutham A Profile Picture
    2 on at

    I tried but was thrown with below error. please help.

    1881.error.jpg

  • Goutham A Profile Picture
    2 on at

    Request to help if anyone has a solution for his.

    I am using 8.2.0.749 crm version

  • Suggested answer
    Goutham A Profile Picture
    2 on at

    I have found the solution for this. for adding memebers to team , i am using AddMembersTeam and it worked fine.Thanks

    var AssociationParameter = { Members: [{ "ownerid": userId}] };

    var url = "crmurl/.../teams(" + id + ")/Microsoft.Dynamics.CRM.AddMembersTeam"

  • Community Member Profile Picture
    on at

    When I use AddMembersTeam I get "Failed to insert audit record"

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans