日期之间所有帐户的MS Dynamics审核历史记录



我有这样的代码,它将提取所提到的特定Guid的审计历史细节(见第二行注释(:

//Create a new RetrieveAttributeChangeHistoryRequest  
RetrieveAttributeChangeHistoryRequest req = new RetrieveAttributeChangeHistoryRequest();
//Set the target Entity......... Needs to be modified so ALL account records are returned instead of the specific one  mentioned              
req.Target = new EntityReference("accounts", new Guid("468f8db5-4f98-eb11-57ee-0006ffc2587a"));
//Set the attribute you want to retrieve specifically........ needs to be modified so that only records between two dates are returned              
req.AttributeLogicalName = "credit_limit";
//Execute the request against the OrgService
RetrieveAttributeChangeHistoryResponse resp = (RetrieveAttributeChangeHistoryResponse)_service.Execute(req);
AuditDetailCollection details = resp.AuditDetailCollection;
foreach (var detail in details.AuditDetails)
{
if (detail.GetType() == typeof(AttributeAuditDetail))
{
AttributeAuditDetail attributeDetail = (AttributeAuditDetail)detail;
}
}

我需要对此进行修改,以便它在两个日期(例如:4月1日至4月7日(之间创建的所有帐户记录中循环,而不是提供一个特定的Guid。Microsoft没有提供可以做到这一点的示例。

非常感谢你的帮助。

尝试下面的代码应该可以,可能是我这边的拼写错误,但应该可以

// Define Condition Values
var query_createdon = "2020-07-15T00:00:00+02:00";
var query_createdon1 = "2021-02-12T00:00:00+01:00";
// Instantiate QueryExpression query
var query = new QueryExpression("account");
// Add columns to query.ColumnSet
query.ColumnSet.AddColumns("createdon", "name", "accountid");
// Define filter query.Criteria
query.Criteria.AddCondition("createdon", ConditionOperator.GreaterThan, query_createdon);
query.Criteria.AddCondition("createdon", ConditionOperator.LessThan, query_createdon1);
EntityCollection _accounts = _service.RetrieveMultiple(query);
foreach(var _account in _accounts.Entities){
//Create a new RetrieveAttributeChangeHistoryRequest  
RetrieveAttributeChangeHistoryRequest req = new RetrieveAttributeChangeHistoryRequest();
//Set the target Entity......... Needs to be modified so ALL account records are returned instead of the specific one  mentioned              
req.Target = new EntityReference("accounts", _account.Id);
//Set the attribute you want to retrieve specifically........ needs to be modified so that only records between two dates are returned              
req.AttributeLogicalName = "credit_limit";
//Execute the request against the OrgService
RetrieveAttributeChangeHistoryResponse resp = (RetrieveAttributeChangeHistoryResponse)_service.Execute(req);
AuditDetailCollection details = resp.AuditDetailCollection;
foreach (var detail in details.AuditDetails)
{
if (detail.GetType() == typeof(AttributeAuditDetail))
{
AttributeAuditDetail attributeDetail = (AttributeAuditDetail)detail;
var recordID = "(no value)";
var recordName = "(no value)";
var changedBy = "(no value)";
if (attributeDetail.OldValue.Contains("credit_limit"))
///          need to set the value of recordID in here but I don't know how
///          need to set the value of recordName in here but I don't know how
///          need to set the value of changedBy in here but I don't know how
Console.WriteLine("Record ID: "+recordID);    /// returns (no value) because I don't know how to get the recordID value
Console.WriteLine("Record Name: "+recordName);    /// returns (no value) because I don't know how to get the recordName value
Console.WriteLine("Changed By: "+changedBy);    /// returns (no value) because I don't know how to get the changed by value
}
}
}

简而言之,你需要的是两次约会,然后拿到所有的账户。一旦你有了所有这些账户,你需要循环浏览,然后获得每个账户的审计历史记录。

注意:如果您获取的记录超过5千条,您可能需要查看分页,因为默认情况下crm只检索5千条记录

// Define Condition Values
var query_createdon = "2020-07-15T00:00:00+02:00";
var query_createdon1 = "2021-02-12T00:00:00+01:00";
// Instantiate QueryExpression query
var query = new QueryExpression("account");
// Add columns to query.ColumnSet
query.ColumnSet.AddColumns("createdon", "name", "accountid");
// Define filter query.Criteria
query.Criteria.AddCondition("createdon", ConditionOperator.GreaterThan, query_createdon);
query.Criteria.AddCondition("createdon", ConditionOperator.LessThan, query_createdon1);
EntityCollection _accounts = _service.RetrieveMultiple(query);

相关内容

  • 没有找到相关文章

最新更新