admin 管理员组

文章数量: 887021

1、组织服务方法

添加N:N关系

service.Associate("实体1名称", 实体1ID, 
new Relationship("实体1实体2中间表"), 
new EntityReferenceCollection(new EntityReference("实体2", 实体2ID)));


删除N:N关系
 

service.Disassociate("实体1名称", 实体1ID, 
new Relationship("实体1实体2中间表"), 
new EntityReferenceCollection(new EntityReference("实体2", 实体2ID)));

例如

//团队添加用户
Service.Associate("team", teamId, 
new Relationship("teammembership_association"), 
new EntityReferenceCollection() { new EntityReference("systemuser", systemuser) });
//移除团队用户
Service.Disassociate("team", teamId, 
new Relationship("teammembership_association"), 
new EntityReferenceCollection() { new EntityReference("systemuser", systemuser) });

2、Request

添加N:N关系

// Create the request object and set the monikers with the
// teamprofiles_association relationship.

AssociateRequest teamToProfile = new AssociateRequest
{
    Target = new EntityReference(FieldSecurityProfile.EntityLogicalName, _profileId),
    RelatedEntities = new EntityReferenceCollection
    {
        new EntityReference(Team.EntityLogicalName, _teamId)
    },
    Relationship = new Relationship("teamprofiles_association")
};

// Execute the request.
svc.Execute(teamToProfile);

删除N:N关系

// Create the request object and set the monikers with the
// teamprofiles_association relationship.

DisassociateRequest teamToProfile = new DisassociateRequest 
{
    Target = new EntityReference(FieldSecurityProfile.EntityLogicalName, _profileId),
    RelatedEntities = new EntityReferenceCollection
    {
        new EntityReference(Team.EntityLogicalName, _teamId)
    },
    Relationship = new Relationship("teamprofiles_association")
};

// Execute the request.
svc.Execute(teamToProfile);

3、JavaScript

添加N:N关系

POST [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000002)/opportunity_customer_accounts/$ref HTTP/1.1   
Content-Type: application/json   
Accept: application/json   
OData-MaxVersion: 4.0   
OData-Version: 4.0  
  
{  
"@odata.id":"[Organization URI]/api/data/v9.0/opportunities(00000000-0000-0000-0000-000000000001)"  
}

删除N:N关系

DELETE [Organization URI]/api/data/v9.0/accounts(00000000-0000-0000-0000-000000000002)/opportunity_customer_accounts(00000000-0000-0000-0000-000000000001)/$ref HTTP/1.1  
Accept: application/json  
OData-MaxVersion: 4.0  
OData-Version: 4.0

附:

下表列出了默认实体之间的“N:N”关系中所使用的相交实体。

IntersectEntity

MtoM_SchemaName

MtoM_Entity1

MtoM_Entity2

accountleads

accountleads_association

account

lead

campaignactivityitem

campaignactivitylist_association

campaignactivity

list

campaignactivityitem

campaignactivitysalesliterature_association

campaignactivity

salesliterature

campaignitem

campaigncampaign_association

campaign

campaign

campaignitem

campaignlist_association

campaign

list

campaignitem

campaignproduct_association

campaign

product

campaignitem

campaignsalesliterature_association

campaign

salesliterature

competitorproduct

competitorproduct_association

competitor

product

competitorsalesliterature

competitorsalesliterature_association

salesliterature

competitor

connectionroleassociation

connectionroleassociation_association

connectionrole

connectionrole

contactinvoices

contactinvoices_association

invoice

contact

contactleads

contactleads_association

contact

lead

contactorders

contactorders_association

salesorder

contact

contactquotes

contactquotes_association

quote

contact

entitlementcontacts

entitlementcontacts_association

contact

entitlement

entitlementproducts

product_entitlement_association

product

entitlement

entitlementtemplateproducts

product_entitlementtemplate_association

product

entitlementtemplate

leadcompetitors

leadcompetitors_association

lead

competitor

leadproduct

leadproduct_association

lead

product

listmember

listaccount_association

list

account

listmember

listcontact_association

list

contact

listmember

listlead_association

list

lead

opportunitycompetitors

opportunitycompetitors_association

opportunity

competitor

productassociation

productassociation_association

product

product

productsalesliterature

productsalesliterature_association

product

salesliterature

productsubstitute

productsubstitute_association

product

product

queuemembership

queuemembership_association

queue

systemuser

roleprivileges

roleprivileges_association

privilege

role

roletemplateprivileges

roletemplateprivileges_association

roletemplate

privilege

servicecontractcontacts

servicecontractcontacts_association

contact

contract

subscriptionmanuallytrackedobject

contact_subscription_association

subscription

contact

subscriptionmanuallytrackedobject

task_subscription_association

subscription

task

systemuserprofiles

systemuserprofiles_association

systemuser

fieldsecurityprofile

systemuserroles

systemuserroles_association

systemuser

role

teammembership

teammembership_association

team

systemuser

teamprofiles

teamprofiles_association

team

fieldsecurityprofile

teamroles

teamroles_association

team

role

本文标签: 代码 关系 Dynamics CRM