Hi All,
I have registered plugin with message Name="Associate" for adding User members to Queue record and subsequently an Audit Log record is created. But i am not able to create Audit Log record while adding User Members to the Queue record. Below is the code that is running for this:
else if (relatedEntity[0].LogicalName.Equals("systemuser") && (targetEntity.LogicalName.Equals("queue") && relationship.SchemaName.Equals("queuemembership_association")))
{
foreach (EntityReference er in relatedEntity)
{
string QueueName = helper.RetrieveName(new EntityReference(targetEntity.LogicalName, targetEntity.Id));
string UserName = helper.RetrieveName(new EntityReference(er.LogicalName, er.Id));
if (context.MessageName=="Associate")
{
desc = UserName + "is addded to " + QueueName + " Queue";
}
else if (context.MessageName.Equals("Disassociate") && targetEntity.LogicalName.Equals("queue"))
{
desc = UserName + " Removed From" + QueueName + " Queue";
}
helper.CreateLog(QueueName, targetEntity.LogicalName, EventOptions.Membership, desc, context.InitiatingUserId);
}
}
public string RetrieveName(EntityReference entityref)
{
Entity entity = service.Retrieve(entityref.LogicalName, entityref.Id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
if (entity.Contains("name"))
{
return entity["name"].ToString();
}
else if (entity.Contains("fullname"))
{
return entity["fullname"].ToString();
}
return string.Empty;
}
*This post is locked for comments