I am trying to fetch the audit history of a user from CRM. My code is shown below. However at run time i get an exception "audit With Id = c011f583-8741-e211-bce3-78e7d1622fbb Does Not Exist".
Am I missing something?. Please suggest.
Entity entUser = (from name in context.CreateQuery(Constant.SystemUser.EntityLogicalName)
where name.GetAttributeValue<string>(Constant.SystemUser.FullName) == "Sample"
select name).FirstOrDefault();
var auditDetailsRequest = new RetrieveAuditDetailsRequest
{
AuditId = entUser.Id
};
using (OrganizationServiceProxy organizationProxy = CRMHelper.GetServiceProxy())
{
var auditDetailsResponse = organizationProxy.Execute(auditDetailsRequest);
}
*This post is locked for comments
if you want to retrieve audit details based on the audit id then you can use RetrieveAuditDetailsRequest.
but here you are trying to retrieve audit details based on user id then you need to use RetrieveRecordChangeHistoryRequest
RetrieveRecordChangeHistoryRequest changeRequest = new RetrieveRecordChangeHistoryRequest(); changeRequest.Target = new EntityReference("systemuser", entUser.Id);
we also have RetrieveAttributeChangeHistoryRequest SDK request to retrieve audit details for a specific attribute
var attributeChangeHistoryRequest = new RetrieveAttributeChangeHistoryRequest { Target = new EntityReference( "incident", new Guid("D22F869B-F79C-E611-80F0-3863BB35EF70")), AttributeLogicalName = "statuscode" };
Regards,
Siraj
It because you're trying to use id of your user, but AuditId parameter - the ID of the Audit record to retrieve
If you want to get history of changes use RetrieveRecordChangeHistoryRequest (https://msdn.microsoft.com/en-us/library/gg309735.aspx)
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156