public void GetConnectionRole()
{
try
{
var Kategori = new
{
Business = 1,
Family = 2,
Social = 3,
Sales = 4,
Other = 5
};
ConnectionRole cRole = new ConnectionRole
{
Name = "Ornek Connection Role",
Category = new OptionSetValue(Kategori.Family)
};
_connectionRoleId = Factory.serviceProxy.Create(cRole);
Console.WriteLine("Created {0}.", cRole.Name);
// Create a related Connection Role Object Type Code record for Account
ConnectionRoleObjectTypeCode newAccountConnectionRole1TypeCode
= new ConnectionRoleObjectTypeCode
{
ConnectionRoleId = new EntityReference(
ConnectionRole.EntityLogicalName, _connectionRoleId),
AssociatedObjectTypeCode = Account.EntityLogicalName
};
Factory.serviceProxy.Create(newAccountConnectionRole1TypeCode);
Console.WriteLine(
"Created a related Connection Role 1 Object Type Code record for Account."
);
// Create a related Connection Role Object Type Code record for Contact
ConnectionRoleObjectTypeCode newContactConnectionRoleTypeCode
= new ConnectionRoleObjectTypeCode
{
ConnectionRoleId = new EntityReference(
ConnectionRole.EntityLogicalName, _connectionRoleId),
AssociatedObjectTypeCode = Contact.EntityLogicalName
};
Factory.serviceProxy .Create(newContactConnectionRoleTypeCode);
Console.WriteLine(
"Created a related Connection Role Object Type Code record for Contact."
);
// Associate the connection role with itself.
AssociateRequest associateConnectionRoles = new AssociateRequest
{
Target = new EntityReference(ConnectionRole.EntityLogicalName,
_connectionRoleId),
RelatedEntities = new EntityReferenceCollection()
{
new EntityReference(ConnectionRole.EntityLogicalName,
_connectionRoleId)
},
// The name of the relationship connection role association
// relationship in MS CRM.
Relationship = new Relationship()
{
PrimaryEntityRole = EntityRole.Referencing, // Referencing or Referenced based on N:1 or 1:N reflexive relationship.
SchemaName = "connectionroleassociation_association"
}
};
Factory.serviceProxy .Execute(associateConnectionRoles);
Console.WriteLine("Associated the connection role with itself.");
Connection newConnection = new Connection
{
Record1Id = new EntityReference(Account.EntityLogicalName,
_accountId),
Record1RoleId = new EntityReference(ConnectionRole.EntityLogicalName,
_connectionRoleId),
Record2RoleId = new EntityReference(ConnectionRole.EntityLogicalName,
_connectionRoleId),
Record2Id = new EntityReference(Contact.EntityLogicalName,
_contactId)
};
_connectionId =Factory.serviceProxy.Create(newConnection);
Console.WriteLine(
"Created a connection between the account and the contact.");
}
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
{
throw;
}
}
Hiç yorum yok:
Yorum Gönder