Goal
Show how to count distinct records whose tracked columns were changed by a specific user (e.g., a Power Pages account), using Audit History only.
Why use a plugin for this
-
The audit “what changed” detail lives in
RetrieveAuditDetails
/AttributeAuditDetail
. Plugins call these messages directly, run server-side, and respect Dataverse security. -
Power Automate has no first-class audit-detail action. You’d need custom calls and would still loop per audit row, slower and harder to manage.
-
A plugin exposed via a Custom Action gives a clean, reusable API.
Demo scenario
Count how many hx_demoentity
records were updated by the portal user and touched any of these columns: hx_field1
, hx_field2
. Optional date window.
Minimal plugin (Custom Action)
What it does
-
Filters
audit
by entity type, Update events, specific user, optional time window. -
For each audit row, pulls
AttributeAuditDetail
and checks if any tracked field was in the change set (presence-only; values not compared). -
Adds
objectid
to aHashSet<Guid>
and returns its size.
Setup checklist
-
Enable auditing on
hx_demoentity
and onhx_field1
,hx_field2
. -
Create Environment Variable
hx_TargetUserFullName
with the portal account’s Full Name. -
Register plugin on a Custom Action
hx_CountChangedRecords
with outputsCount
. -
Call the action with optional UTC
StartOn
andEndOn
.
Performance notes
-
Each audit row requires a
RetrieveAuditDetails
call. Large windows or heavy users can produce many rows. -
For demos and small windows this is fine. For production scale:
-
Run the action asynchronously or offload to a worker (Azure Function via webhook).
-
Keep time windows tight.
-
Consider writing a lightweight “change marker” on the target entity in a separate plugin when portal saves occur, so counting later is a single query.
-
Variations
-
Track multiple entities: repeat the loop over a
SourceDef[]
list. -
Track different fields per entity.
-
Return both count and the list of IDs for downstream reporting.
No comments:
Post a Comment