How to link two records with JavaScript and a n:m relationship

I have a many-to-many relationship between two entities. I know Dynamics CRM creates an intersect table for that in the database. And I know how I can retrieve records with a fetch command from that auto created entity.

But now I want to dynamically add new records to that table using JavaScript. Is this possible?

I've tried to create a new record for this type, but then I got the following error.

The create method does not support entities of type ["relationship_entity_name"].



The JavaScript SDK is not the clearest on this point, but the basics of it is that the SDK does not allow direct insertion into intersect tables. It only allows calls to the Associate method. Below are two TechNet links which may lead you in the right direction.

Additionally, Avanade has done a wonderful job in making a CRM JavaScript library (updated to reference publicly available which includes an Associate helper method.

Finally, some sample code:

function AssociateEntities(moniker1, moniker2, relationshipName) {
    var xml;
    var resultXml;

    xml = "<Execute xmlns=''>";
    xml += "<Request xsi:type='AssociateEntitiesRequest'>";
    xml += "<Moniker1><Id xmlns=''>" + moniker1[0].id + "</Id>";
    xml += "<Name xmlns=''>" + moniker1[0].entityType + "</Name></Moniker1>";
    xml += "<Moniker2><Id xmlns=''>" + moniker2[0].id + "</Id>";
    xml += "<Name xmlns=''>" + moniker2[0].entityType + "</Name></Moniker2>";
    xml += "<RelationshipName>" + relationshipName + "</RelationshipName>";
    xml += "</Request></Execute>";

    resultXml = CallCrmService(xml, "Execute");

    if (resultXml) {
        return "success";
    else {
        return null;


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.