日期之间所有帐户的 MS Dynamics 审计历史记录
MS Dynamics audit history for all accounts between dates
我有这段代码可以提取所提到的特定 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
}
}
}
简而言之,您需要的是介于两者之间的两个日期并获取所有帐户。拥有所有这些帐户后,您需要循环访问然后获取每个帐户的审计历史记录。
注意:如果您要获取超过 5000 条记录,您可能需要查看分页,因为默认情况下 crm 仅检索 5000 条记录
// 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);
我有这段代码可以提取所提到的特定 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
}
}
}
简而言之,您需要的是介于两者之间的两个日期并获取所有帐户。拥有所有这些帐户后,您需要循环访问然后获取每个帐户的审计历史记录。
注意:如果您要获取超过 5000 条记录,您可能需要查看分页,因为默认情况下 crm 仅检索 5000 条记录
// 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);