Hi CRM Dynamites,
In Microsoft Dynamics CRM 2011, a new feature called Connections adds a layer to records organization, allowing users to connect records in an intuitive manner. Connections gives users insight into their company’s records in Dynamics CRM 2011 at a glance. A user can open any record and quickly identify relationships or a hierarchy by looking at that record’s Connections with other records.
Scenario: Suppose u have a Account entity and Contact Entity and u want to create a connection for Account with Contact Entity.
To Create this Connections Programmatically below code can be used :
public void Create_Accc_Contact_Connection(Guid accountid, int objectTypeCode) //Account Entity Obeject Typecode
{
Guid Contact = ContactGUID;
Connection newConnection = new Connection
{
Record1Id = new EntityReference(ContactEntityLogicalName,
Contact),
Record1RoleId = new EntityReference(ConnectionRole.EntityLogicalName,
ContactConnectionRoleId),
Record2RoleId = new EntityReference(ConnectionRole.EntityLogicalName,
AccountConnectionRoleId),
Record2Id = new EntityReference(AccountEntityLogicalName,
accountid)
};
service.Execute(newConnection);
}
To Remove Connection Programmatically between entity below code can be used :
public void Remove_Accc_Contact_Connection(Guid accountid, int objectTypeCode) //Account Entity Obeject Typecode
{
Guid Contact = ContactGUID;
QueryExpression query = new QueryExpression
{
EntityName = Connection.EntityLogicalName,
Criteria =
{
Conditions =
{
new ConditionExpression("record1id", ConditionOperator.Equal, accountid),
new ConditionExpression("record2objecttypecode", ConditionOperator.Equal, objectTypeCode),
new ConditionExpression("record2roleid", ConditionOperator.Equal, Contact)
}
},
};
service.Delete(Connection.EntityLogicalName, ent.Id);
}
Hope this post helps for your requirement
Thanks