Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Not able to create Audit Log Record(custom entity) when adding User records to Queue

Posted on by 255

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

  • Suggested answer
    sandeepstw Profile Picture
    sandeepstw 4,601 on at
    RE: Not able to create Audit Log Record(custom entity) when adding User records to Queue

    Hi,

    Use like this context.MessageName.ToLower() == "associate"

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans