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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Associate a N to N relationship through the web API during Creation in Javascript

(0) ShareShare
ReportReport
Posted on by

Hi,

So I am trying to use the webapi to clone a current record, but I am getting stuck wjen it comes to copying over the contents of the subgrid to the cloned record.  Everyone works until I get to the N to N association where it tells me an array should be there rather then a string, but I have no idea what that should look like. Any help would be appreciated

var serverURL = parent.Xrm.Page.context.getClientUrl(); 
var commitment = {};
commitment["new_name"] = parent.Xrm.Page.getAttribute("new_name").getValue() + " Clone";

//Recipients var allRows = parent.Xrm.Page.getControl("Recipients").getGrid().getRows();
commitment["new_new_commitment_contact@odata.bind"] = "/contacts("+allRows.get(0).getData().getEntity().getEntityReference().id.replace('{',"").replace('}',"")+")";


var req = new XMLHttpRequest(); req.open("POST", serverURL + "/api/data/v8.0/new_commitments", true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("MSCRMCallerID", (parent.Xrm.Page.getAttribute("ownerid").getValue()[0].id.replace('{',"").replace('}',"")));
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 /* complete */ )
{
req.onreadystatechange = null; if (this.status == 204)
{
}
else { var error = JSON.parse(this.response).error; alert(error.message); } } };
req.send(JSON.stringify(commitment));


 


*This post is locked for comments

I have the same question (0)
  • Verified answer
    Andreas Cieslik Profile Picture
    9,267 on at

    As you can read here:

    msdn.microsoft.com/.../gg328090.aspx

    odata.bind is only valid for single-valued navigation properties (a lookup field)

    and not for collection-valued navigation properties (n:n)

    You would first need to create the commitment record then you could actually associate an existing contact like this:

    msdn.microsoft.com/.../mt607875.aspx

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans