问题
On a custom entity I enabled a single field for auditing which seems to be working fine. But there are many, many more audit records having changed date, changed by (both user and service accounts) and event of Update but blank changed field, old value and new value columns. Opening one of these "blank" records shows the message given in the title.
And when you open one of them what you see is no table but the statement "the fields changed by this action are not enabled for audit tracking".
Yeah, I know. All but one of the fields is not enabled for audit tracking. Clearly these are events generated by a plugin or workflow.
Why is it giving me these and how do I make it stop?
回答1:
Why is it giving me these
Because the fields are being updated. As you mention this is likely by a plugin or a workflow.
Plugins often update fields by mistake when they forget to instantiate a new Entity
and give it only the necessary attributes to update:
Instantiating a new entity
var smallEntity = new Entity { Id = new Guid("entityId"), LogicalName = "entityName" };
smallEntity["firstname"] = "newName";
...
service.Update(smallEntity);
Updating all fields unnecessarily
var bigEntity = service.Retrieve(new Guid("entityId"), "entityName", new ColumnSet(true));
bigEntity["firstname"] = "newName";
...
service.Update(bigEntity);
smallEntity
contains only one attribute. When Update
is called, audit history will show only one field as having updated.
bigEntity
contains every single entity attribute because it was retrieved using new ColumnSet(true)
. When Update
is called, audit history will show all fields as having updated, even though only "firstname"
has actually changed.
how do I make it stop?
One option would be to filter the audit history view to only show the field you're interested in:
回答2:
Audits can be enabled in 3 levels namely Organization, Entity & Attribute level.
System will start collecting the attribute values which are all audit enabled, for capturing the old value & new value (not current value).
Your explicit updates in plugin/workflow initiated audit on entity but the attributes updated on such service updates were not eligible (may be unchanged values) for value capturing.
If you see the audit table in database also, the row will be empty with ~ and , (without column names & stored old/new values)
You cannot stop collecting this, but can find out the fields by enabling audit on all fields & identify the plugin steps. Then initiate the entity object like Dave mentioned & avoid this.
Update: Am 100% right. This happened for me when I associate a lookup (which is not audit enabled)
来源:https://stackoverflow.com/questions/45440057/dynamics-crm-2013-audit-logs-have-blank-records