如何使用JavaScript和n:m关系链接两个记录 [英] How to link two records with JavaScript and a n:m relationship

查看:88
本文介绍了如何使用JavaScript和n:m关系链接两个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在两个实体之间有多对多关系。我知道 Dynamics CRM 为此数据库创建了一个相交表。而且我知道如何使用自动创建的实体中的提取命令检索记录。



但是现在我想使用JavaScript向该表动态添加新记录。这可能吗?



我尝试为此类型创建新记录,但是随后出现以下错误。


create方法不支持类型为[ relationship_entity_name]的实体。



解决方案

在这一点上,JavaScript SDK并不是最清晰的,但是其基础是SDK不允许直接插入到相交表中。它仅允许调用 Associate 方法。以下是两个 TechNet 链接,它们可能会引导您朝正确的方向前进。





此外,Avanade在制作 CRM JavaScript库(已更新为引用archive.org 可用,其中包括 Associate 辅助方法。



最后,提供一些示例代码:



< pre class = lang-js prettyprint-override> function AssociateEntities(moniker1,moniker2,relationshipName){
var xml;
var resultXml;

xml =< Execute xmlns ='http://schemas.microsoft.com/crm/2007/WebServices'>;
xml + =< Request xsi:type ='AssociateEntitiesRequest'>;;
xml + =< Moniker1>< Id xmlns ='http://schemas.microsoft.com/crm/2006/CoreTypes'> + moniker1 [0] .id +< / Id>;
xml + =<名称xmlns ='http://schemas.microsoft.com/crm/2006/CoreTypes'> + moniker1 [0] .entityType +< / Name>< / Moniker1>;
xml + =< Moniker2>< Id xmlns ='http://schemas.microsoft.com/crm/2006/CoreTypes'> + moniker2 [0] .id +< / Id>;
xml + =<名称xmlns ='http://schemas.microsoft.com/crm/2006/CoreTypes'> + moniker2 [0] .entityType +< / Name>< / Moniker2>;
xml + =< RelationshipName> + RelationshipName +< / RelationshipName>;
xml + =< / Request>< / Execute>;

resultXml = CallCrmService(xml, Execute);

if(resultXml){
返回成功;
}
else {
返回null;
}
}


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 archive.org) publicly available which includes an Associate helper method.

Finally, some sample code:

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

    xml = "<Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>";
    xml += "<Request xsi:type='AssociateEntitiesRequest'>";
    xml += "<Moniker1><Id xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>" + moniker1[0].id + "</Id>";
    xml += "<Name xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>" + moniker1[0].entityType + "</Name></Moniker1>";
    xml += "<Moniker2><Id xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>" + moniker2[0].id + "</Id>";
    xml += "<Name xmlns='http://schemas.microsoft.com/crm/2006/CoreTypes'>" + moniker2[0].entityType + "</Name></Moniker2>";
    xml += "<RelationshipName>" + relationshipName + "</RelationshipName>";
    xml += "</Request></Execute>";

    resultXml = CallCrmService(xml, "Execute");

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

这篇关于如何使用JavaScript和n:m关系链接两个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆