<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[People Analytics &amp; HRIS - Medium]]></title>
        <description><![CDATA[A publication on human resources information technology, people analytics in Microsoft ecosystem (and beyond). - Medium]]></description>
        <link>https://medium.com/people-analytics-hris?source=rss----5ccbf6d66090---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>People Analytics &amp;amp; HRIS - Medium</title>
            <link>https://medium.com/people-analytics-hris?source=rss----5ccbf6d66090---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:30:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/people-analytics-hris" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Designing Robust Employee Lifecycle Integrations with D365 F&O Pt 3]]></title>
            <link>https://medium.com/people-analytics-hris/designing-robust-employee-lifecycle-integrations-with-d365-f-o-1899a3559d8e?source=rss----5ccbf6d66090---4</link>
            <guid isPermaLink="false">https://medium.com/p/1899a3559d8e</guid>
            <category><![CDATA[dynamics-365]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[people-analytics]]></category>
            <dc:creator><![CDATA[Jesse Ruiz (she/they)]]></dc:creator>
            <pubDate>Sat, 31 Jan 2026 16:42:38 GMT</pubDate>
            <atom:updated>2026-01-31T16:42:36.785Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 3: Testing, Debugging, and Production Operations</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tGY0ylZ3-H7NisSZ35GqrA.png" /></figure><p>In this series of articles, I discuss a data integration project involving Dynamics 365 Finance and Operations and ADP. This project required orchestrating disparate HR systems to stay in sync with one another using OData integration and Power Automate.</p><p>This third article focuses on comprehensive testing and systematic debugging.</p><h4>The Reality of Production Operations</h4><p>You’ve built a termination workflow that updates 5 entities in the correct order with proper error handling. You’ve tested it once and it worked. Ship it? Not yet.</p><p>Production is messy:</p><p>- Employees with multiple position assignments</p><p>- Missing hierarchy nodes</p><p>- Concurrent updates from other systems</p><p>- Network timeouts during multi-step workflows</p><p>- Invalid reason codes in the payload</p><p>- Employees who are already partially terminated</p><p>If your testing strategy is “ran it once, looked good,” you’re going to spend your weekends fixing production incidents.</p><p>This article walks through building a comprehensive test suite and debugging production failures systematically.</p><p>—</p><h3>Testing Strategies</h3><h4>Test Level 1</h4><p>Scenario: Standard voluntary resignation with 2 weeks notice</p><p><strong>Setup:</strong></p><p>1. Create a complete employee record:</p><p>- Person (Party)</p><p>- Worker with PersonnelNumber</p><p>- Employee contract</p><p>- Single position assignment</p><p>- Position hierarchy node (reports to manager)</p><p>- Position worker assignment</p><p>2. Run termination flow with:</p><p>- TerminationDate: 2 weeks from today</p><p>- LastDateWorked: 1 day before termination</p><p>- Reason: “RESIGN”</p><p><strong>Expected Results:</strong></p><ul><li>Employees.TerminationDate = specified date</li><li>Employees.EmploymentEndDate = specified date</li><li>Employees.LastDateWorked = specified date</li><li>Workers.WorkerStatus = “Terminated”</li><li>Workers.SummaryValidTo = termination date</li><li>Positions.AvailableForAssignment = “Yes”</li><li>PositionHierarchies.ValidTo = termination date</li><li>PositionWorkerAssignments.ValidTo = termination date</li><li>People.PartyNumber still exists (not deleted)</li></ul><p><strong>Validation Query:</strong></p><pre>-- Check all entities for PersonnelNumber &#39;199199&#39;<br>SELECT <br>    e.TerminationDate,<br>    e.EmploymentEndDate,<br>    w.WorkerStatus,<br>    w.SummaryValidTo,<br>    p.AvailableForAssignment,<br>    ph.ValidTo AS HierarchyValidTo,<br>    pwa.ValidTo AS AssignmentValidTo<br>FROM Workers w<br>LEFT JOIN Employees e ON w.PartyNumber = e.PartyNumber<br>LEFT JOIN PositionWorkerAssignments pwa ON w.PersonnelNumber = pwa.PersonnelNumber<br>LEFT JOIN Positions p ON pwa.PositionId = p.PositionId<br>LEFT JOIN PositionHierarchies ph ON p.PositionId = ph.ChildPositionId<br>WHERE w.PersonnelNumber = &#39;199199&#39;;</pre><h4>Test Level 2: Edge Cases</h4><h4>Edge Case 1: Employee with Multiple Position Assignments</h4><p>Scenario: Employee holds 2 positions (80% Engineer + 20% Team Lead)</p><p><strong>Setup:</strong></p><blockquote>Worker: PersonnelNumber=’100234&#39;<br>Assignments:<br> 1. PositionId=’POS-001&#39;, FTE=0.8, ValidTo=2154–12–31<br> 2. PositionId=’POS-002&#39;, FTE=0.2, ValidTo=2154–12–31</blockquote><p><strong>Expected Behavior:</strong></p><p>- Both assignments must be closed</p><p>- Both positions marked as available</p><p>- Both hierarchy nodes (if present) closed</p><p><strong>Common Failure:</strong></p><p>Your flow only queries for “the” position (singular)</p><p><strong>Result: </strong>Assignment 1 closed, Assignment 2 still active</p><p>Employee shows as both terminated and active</p><p><strong>Fix: </strong>Flow must loop through all assignments</p><pre>{<br>  &quot;Get_All_Assignments&quot;: {<br>    &quot;type&quot;: &quot;ApiConnection&quot;,<br>    &quot;inputs&quot;: {<br>      &quot;parameters&quot;: {<br>        &quot;table&quot;: &quot;PositionWorkerAssignments&quot;,<br>        &quot;$filter&quot;: &quot;PersonnelNumber eq &#39;@{variables(&#39;PersonnelNumber&#39;)}&#39; and ValidTo gt @{utcNow()}&quot;<br>      }<br>    }<br>  },<br>  &quot;For_Each_Assignment&quot;: {<br>    &quot;type&quot;: &quot;Foreach&quot;,<br>    &quot;foreach&quot;: &quot;@body(&#39;Get_All_Assignments&#39;)?[&#39;value&#39;]&quot;,<br>    &quot;actions&quot;: {<br>      &quot;Close_Assignment&quot;: { ... }<br>    }<br>  }<br>}</pre><h4>Edge Case 2: Missing Position Hierarchy Node</h4><p>Scenario: Employee is assigned to a position that has no hierarchy entry (no reporting relationship defined)</p><p><strong>Setup:</strong></p><blockquote>PositionWorkerAssignment exists</blockquote><blockquote>Position exists</blockquote><blockquote>PositionHierarchy: NULL (no record)</blockquote><p><strong>Expected Behavior:</strong></p><p>- Flow should not fail when hierarchy update is attempted</p><p>- Assignment should still be closed</p><p>- Position should still be freed</p><p><strong>Implementation:</strong></p><pre>{<br>  &quot;Check_Hierarchy_Exists&quot;: {<br>    &quot;type&quot;: &quot;ApiConnection&quot;,<br>    &quot;inputs&quot;: {<br>      &quot;parameters&quot;: {<br>        &quot;table&quot;: &quot;PositionHierarchies&quot;,<br>        &quot;$filter&quot;: &quot;ChildPositionId eq &#39;@{variables(&#39;PositionId&#39;)}&#39; and ValidTo gt @{utcNow()}&quot;<br>      }<br>    }<br>  },<br>  &quot;Condition_Has_Hierarchy&quot;: {<br>    &quot;type&quot;: &quot;If&quot;,<br>    &quot;expression&quot;: {<br>      &quot;greater&quot;: [<br>        &quot;@length(body(&#39;Check_Hierarchy_Exists&#39;)?[&#39;value&#39;])&quot;,<br>        0<br>      ]<br>    },<br>    &quot;actions&quot;: {<br>      &quot;Update_PositionHierarchies&quot;: { ... }<br>    },<br>    &quot;else&quot;: {<br>      &quot;actions&quot;: { / skip / }<br>    }<br>  }<br>}</pre><h4>Edge Case 3: Termination at Hire Date (Same-Day Termination)</h4><p>Scenario: Employee hired and terminated on the same day (e.g., failed background check)</p><p><strong>Setup:</strong></p><blockquote>EmploymentStartDate: 2024–12–15</blockquote><blockquote>TerminationDate: 2024–12–15</blockquote><blockquote>LastDateWorked: 2024–12–15 (or NULL?)</blockquote><p><strong>Potential Issue: </strong>Some validation rules expect LastDateWorked &lt; TerminationDate</p><p><strong>Test: </strong>Does your flow handle same-day termination without validation errors?</p><h4>Test Level 3: Idempotency</h4><p>What happens if you run the termination flow twice for the same employee?</p><p><strong>Scenario:</strong></p><p>1. Run termination flow (succeeds)</p><p>2. Employee is now terminated</p><p>3. Run termination flow again (accidental re-trigger)</p><p><strong>Expected Behavior:</strong> Second run should be idempotent (safe to retry)</p><p>Bad Outcomes to Avoid:</p><ul><li>Flow crashes because “employee already terminated”</li><li>Dates get overwritten with different values</li><li>Positions get double-freed (data corruption)</li><li>Error emails sent for every retry</li></ul><p>Good Outcomes:</p><ul><li>Flow detects employee is already terminated</li><li>Skips updates (no-op)</li><li>Returns success</li><li>OR: Updates are truly idempotent (same values = same result)</li></ul><p><strong>Implementation:</strong></p><pre>{<br>  &quot;Check_Already_Terminated&quot;: {<br>    &quot;type&quot;: &quot;ApiConnection&quot;,<br>    &quot;inputs&quot;: {<br>      &quot;parameters&quot;: {<br>        &quot;table&quot;: &quot;Workers&quot;,<br>        &quot;id&quot;: &quot;PersonnelNumber=&#39;@{variables(&#39;PersonnelNumber&#39;)}&#39;&quot;<br>      }<br>    }<br>  },<br>  &quot;Condition_Is_Already_Terminated&quot;: {<br>    &quot;type&quot;: &quot;If&quot;,<br>    &quot;expression&quot;: {<br>      &quot;equals&quot;: [<br>        &quot;@body(&#39;Check_Already_Terminated&#39;)?[&#39;WorkerStatus&#39;]&quot;,<br>        &quot;Terminated&quot;<br>      ]<br>    },<br>    &quot;actions&quot;: {<br>      &quot;Return_Already_Terminated&quot;: {<br>        &quot;type&quot;: &quot;Response&quot;,<br>        &quot;inputs&quot;: {<br>          &quot;statusCode&quot;: 200,<br>          &quot;body&quot;: {<br>            &quot;status&quot;: &quot;already_terminated&quot;,<br>            &quot;message&quot;: &quot;Employee already terminated, no action taken&quot;<br>          }<br>        }<br>      }<br>    },<br>    &quot;else&quot;: {<br>      &quot;actions&quot;: {<br>        / Proceed with termination /<br>      }<br>    }<br>  }<br>}</pre><h4>Test Level 4: Partial Failure Simulation</h4><p>What happens if step 3 (Positions) fails, but steps 1–2 (Employees, Workers) succeeded?</p><p><strong>Scenario:</strong></p><p>1. Employees update: * Success</p><p>2. Workers update: * Success</p><p>3. Positions update: * Fails (invalid PositionId)</p><p>4. Hierarchies update: ⏸️ Never runs (blocked by failure)</p><p>5. Assignments update: ⏸️ Never runs</p><p><strong>Expected State:</strong></p><blockquote>Employees: TerminationDate set</blockquote><blockquote>Workers: Status = “Terminated”</blockquote><blockquote>Positions: Still assigned to terminated worker</blockquote><blockquote>Assignments: Still active</blockquote><p><strong>The Problem: </strong>Employee is terminated but position is not freed. Data is inconsistent.</p><p><strong>What Should Happen:</strong></p><p>1. Error email sent immediately with:</p><p>- PersonnelNumber</p><p>- Failed step (“Update_Positions”)</p><p>- Error message</p><p>- Flow run URL</p><p>2. Manual remediation:</p><p>- Review error (was PositionId wrong?)</p><p>- Fix data in D365</p><p>- Re-run flow OR manually close assignments</p><p>Test: Manually inject a failure (invalid PositionId) and verify:</p><p>- Error email arrives</p><p>- Contains enough info to debug</p><ul><li>Partial state is clear and recoverable</li></ul><h3>Debugging Production Failures: A Systematic Approach</h3><p>The Incident: “Employee 199199 Still Shows as Active”</p><p>It’s 2pm on Friday. HR reports that an employee who was terminated yesterday still appears active in the org chart and payroll reports.</p><p>Here’s how you debug this systematically.</p><p>—</p><h4><strong>Step 1: </strong>Verify the Current State via OData</h4><p>Don’t trust reports. Go directly to the source.</p><p><strong>Query 1: </strong>Check Employee Record</p><pre>GET https://instancename.operations.dynamics.com/data/Employees?$filter=PersonnelNumber eq &#39;199199&#39;<br>Authorization: Bearer {token}</pre><p>Look for:</p><pre>{<br>  &quot;value&quot;: [{<br>    &quot;PartyNumber&quot;: &quot;000199139&quot;,<br>    &quot;TerminationDate&quot;: &quot;2154-12-31T23:59:59Z&quot;,  // * Still infinity date!<br>    &quot;EmploymentEndDate&quot;: &quot;2154-12-31T23:59:59Z&quot;,<br>    &quot;LastDateWorked&quot;: null<br>  }]<br>}</pre><p><strong>Diagnosis: </strong>Employee record was never updated. Termination failed at step 1.</p><p><strong>Query 2: </strong>Check Worker Record</p><pre>GET https://instancename.operations.dynamics.com/data/Workers?$filter=PersonnelNumber eq &#39;199199&#39;</pre><p>Look for:</p><pre>{<br>  &quot;value&quot;: [{<br>    &quot;PersonnelNumber&quot;: &quot;199199&quot;,<br>    &quot;PartyNumber&quot;: &quot;000199139&quot;,<br>    &quot;WorkerStatus&quot;: &quot;Active&quot;,  // * Still active<br>    &quot;SummaryValidTo&quot;: &quot;2154-12-31T23:59:59Z&quot;<br>  }]<br>}</pre><p>Diagnosis: Worker also not updated. Failure happened before or during step 1.</p><h4>Step 2: Find the Flow Run</h4><p>Go to Power Automate:</p><p>1. Navigate to flow: “Employee Termination Workflow”</p><p>2. Click “Run history”</p><p>3. Filter by date: Yesterday</p><p>4. Search for PersonnelNumber in inputs/outputs</p><p>Find the run: Click on the specific execution</p><p>Check status:</p><p>- Succeeded but employee not terminated? → Logic bug (flow thinks it worked)</p><p>- Failed at specific step? → Examine error</p><p>- No run found? → Flow was never triggered</p><h4>Step 3: Examine the Failed Action</h4><p>Click on “Update_Employees” action in the failed run.</p><p>Check inputs:</p><pre>{<br>  &quot;parameters&quot;: {<br>    &quot;dataset&quot;: &quot;instancename.operations.dynamics.com&quot;,<br>    &quot;table&quot;: &quot;Employees&quot;,<br>    &quot;id&quot;: &quot;PartyNumber=&#39;000199139&#39;,EmploymentLegalEntityId=&#39;USMF&#39;&quot;,<br>    &quot;item/TerminationDate&quot;: &quot;2024-12-15T23:59:59Z&quot;,<br>    &quot;item/TerminationReasonCodeId&quot;: &quot;RESGN&quot;  // * Typo!<br>  }<br>}</pre><p>Check outputs:</p><pre>{<br>  &quot;statusCode&quot;: 400,<br>  &quot;body&quot;: {<br>    &quot;error&quot;: {<br>      &quot;code&quot;: &quot;BadRequest&quot;,<br>      &quot;message&quot;: &quot;Invalid TerminationReasonCodeId &#39;RESGN&#39;. Valid codes: RESIGN, TERMED, RETIRE, LAYOFF&quot;<br>    }<br>  }<br>}</pre><p>Root Cause Found: Typo in reason code (“RESGN” instead of “RESIGN”)</p><h4>Step 4: Common Error Patterns and Solutions</h4><p>Error Pattern 1: HTTP 400 — Bad Request</p><p>Error Message:</p><pre>{<br>  &quot;error&quot;: {<br>    &quot;code&quot;: &quot;BadRequest&quot;,<br>    &quot;message&quot;: &quot;The property &#39;TerminationDate&#39; does not exist on type &#39;Employee&#39;.&quot;<br>  }<br>}</pre><p>Cause: Field name typo or wrong entity</p><p>Fix: Check OData metadata for correct field names</p><pre>GET https://instancename.operations.dynamics.com/data/$metadata</pre><p>Search for `&lt;EntityType Name=”Employee”&gt;` and verify property names.</p><p>Error Pattern 2: HTTP 404 — Not Found</p><p>Error Message:</p><pre>{<br>  &quot;error&quot;: {<br>    &quot;code&quot;: &quot;NotFound&quot;,<br>    &quot;message&quot;: &quot;Resource not found for the segment &#39;Employees&#39;.&quot;<br>  }<br>}</pre><p>Cause: Incorrect entity set name or composite key</p><p>Common mistakes:</p><p>- `Employee` vs `Employees` (singular vs plural)</p><p>- Missing part of composite key: `PartyNumber=’…’` (missing `,EmploymentLegalEntityId`)</p><p>Error Pattern 3: HTTP 412 — Precondition Failed</p><p>Error Message:</p><pre>{<br>  &quot;error&quot;: {<br>    &quot;code&quot;: &quot;PreconditionFailed&quot;,<br>    &quot;message&quot;: &quot;The etag value does not match the current resource version.&quot;<br>  }<br>}</pre><p>Cause: Concurrent update (someone else modified the record)</p><p>Fix: Retry the operation (GET fresh data, then PATCH)</p><p>Error Pattern 4: HTTP 500 — Internal Server Error</p><p>Error Message:</p><pre>{<br>  &quot;error&quot;: {<br>    &quot;code&quot;: &quot;InternalServerError&quot;,<br>    &quot;message&quot;: &quot;An error occurred while processing this request.&quot;<br>  }<br>}</pre><p>Cause: D365 backend issue (business logic validation, database constraint, etc.)</p><p>Debugging:</p><p>1. Check D365 event logs (if you have access)</p><p>2. Try the same update via D365 UI (does it work manually?)</p><p>3. Open support ticket with Microsoft (include correlation-id from response headers)</p><h4>Step 5: Manual Remediation</h4><p>Once you’ve found the root cause, you need to fix the current broken state.</p><p><strong>Option 1: Re-run the Flow</strong></p><p>1. Fix the issue (e.g., correct the reason code typo)</p><p>2. Re-run the flow for PersonnelNumber ‘199199’</p><p>3. Verify all entities updated correctly</p><p><strong>Option 2: Manual Update via OData</strong></p><p>If the flow can’t be easily re-run, update directly:</p><pre>PATCH https://instancename.operations.dynamics.com/data/Employees(PartyNumber=&#39;000199139&#39;,EmploymentLegalEntityId=&#39;USMF&#39;)<br>Content-Type: application/json<br>Authorization: Bearer {token}<br><br>{<br>  &quot;TerminationDate&quot;: &quot;2024-12-15T23:59:59Z&quot;,<br>  &quot;EmploymentEndDate&quot;: &quot;2024-12-15T23:59:59Z&quot;,<br>  &quot;LastDateWorked&quot;: &quot;2024-12-14T00:00:00Z&quot;,<br>  &quot;TerminationReasonCodeId&quot;: &quot;RESIGN&quot;<br>}</pre><p>Then update Workers, Positions, etc. in sequence.</p><p><strong>Option 3: Fix via D365 UI</strong></p><p>If you’re not comfortable with OData:</p><p>1. Navigate to Human Resources &gt; Workers &gt; Employee</p><p>2. Search for PersonnelNumber</p><p>3. Manually enter termination dates</p><p>4. Update position assignments</p><h3>Alerting Patterns for Production</h3><h4>Alert Level 1: Individual Failure Notification</h4><p>When: Any termination flow fails</p><p>Who: HR integrations team</p><p>Content:</p><blockquote>Subject: Termination Failed: PersonnelNumber 199199</blockquote><blockquote>Failed Step: Update_Employees</blockquote><blockquote>Error Code: 400 Bad Request</blockquote><blockquote>Error Message: Invalid TerminationReasonCodeId ‘RESGN’</blockquote><blockquote>Flow Run: <a href="https://make.powerautomate.com/environments/.../runs/...">https://make.powerautomate.com/environments/.../runs/...</a></blockquote><blockquote>Action Required:</blockquote><blockquote>1. Review error details in flow run history</blockquote><blockquote>2. Correct data issue</blockquote><blockquote>3. Re-run termination for this employee</blockquote><p>Implementation: Covered in Part 2 (“Send_Error_Email” action)</p><h4>Alert Level 2: Aggregate Failure Monitoring</h4><p>When: Multiple failures in a short time window (potential systemic issue)</p><p>Who: Platform team + HR operations</p><p>Example: 10 terminations failed in the last hour</p><p>Implementation:</p><pre>{<br>  &quot;Log_Failure_to_Table&quot;: {<br>    &quot;type&quot;: &quot;ApiConnection&quot;,<br>    &quot;inputs&quot;: {<br>      &quot;host&quot;: { &quot;connectionReferenceName&quot;: &quot;shared_sql&quot; },<br>      &quot;parameters&quot;: {<br>        &quot;table&quot;: &quot;TerminationFailureLog&quot;,<br>        &quot;item&quot;: {<br>          &quot;PersonnelNumber&quot;: &quot;@{variables(&#39;PersonnelNumber&#39;)}&quot;,<br>          &quot;FailedStep&quot;: &quot;@{actions(&#39;Update_Employees&#39;)?[&#39;name&#39;]}&quot;,<br>          &quot;ErrorMessage&quot;: &quot;@{body(&#39;Update_Employees&#39;)?[&#39;error&#39;]?[&#39;message&#39;]}&quot;,<br>          &quot;FlowRunId&quot;: &quot;@{workflow()?[&#39;run&#39;]?[&#39;name&#39;]}&quot;,<br>          &quot;Timestamp&quot;: &quot;@{utcNow()}&quot;<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>Then set up an Azure Monitor alert:</p><pre>Query: SELECT COUNT() FROM TerminationFailureLog WHERE Timestamp &gt; DATEADD(hour, -1, GETUTCDATE())<br>Condition: Result &gt; 10<br>Action: Send email to platform team</pre><h4>Alert Level 3: Data Quality Monitoring</h4><p>When: Inconsistent state detected (e.g., Worker=Terminated but Employee.TerminationDate=infinity)</p><p>Implementation: Scheduled validation query</p><pre>-- Run this query daily via Azure Automation or Logic App<br>SELECT <br>    w.PersonnelNumber,<br>    w.WorkerStatus,<br>    e.TerminationDate,<br>    e.EmploymentEndDate<br>FROM Workers w<br>JOIN Employees e ON w.PartyNumber = e.PartyNumber<br>WHERE <br>    w.WorkerStatus = &#39;Terminated&#39;<br>    AND e.TerminationDate = &#39;2154-12-31 23:59:59&#39;  -- Still &quot;infinity&quot;</pre><p>If this returns rows, data is inconsistent.</p><h3>Production Checklist</h3><p>Before deploying your termination workflow to production:</p><p>Testing</p><p>- [ ] Golden path tested (standard resignation)</p><p>- [ ] Multiple position assignments tested</p><p>- [ ] Missing hierarchy node handled gracefully</p><p>- [ ] Same-day termination tested</p><p>- [ ] Idempotency verified (re-running flow is safe)</p><p>- [ ] Partial failure generates error notification</p><p>- [ ] All error messages include PersonnelNumber and flow run URL</p><p>Error Handling</p><p>- [ ] Every entity update has explicit error handling</p><p>- [ ] Failures send immediate notifications</p><p>- [ ] Error messages are actionable (not just “it failed”)</p><p>- [ ] Concurrent updates handled (412 errors)</p><p>Monitoring</p><p>- [ ] Individual failure alerts configured</p><p>- [ ] Aggregate failure monitoring in place</p><p>- [ ] Data quality validation scheduled (daily)</p><p>- [ ] Flow run history retention configured (90+ days)</p><p>Documentation</p><p>- [ ] Runbook created for common failure scenarios</p><p>- [ ] OData query guide for manual verification</p><p>- [ ] Manual remediation steps documented</p><p>- [ ] On-call playbook updated</p><p>Operational Readiness</p><p>- [ ] Support team trained on debugging flow failures</p><p>- [ ] Access to flow run history granted to support</p><p>- [ ] Process for manual remediation documented</p><p>- [ ] Escalation path defined (when to engage platform team vs. Microsoft support)</p><h4>Key Takeaways from Part 3</h4><ul><li>Test beyond the golden path — Edge cases are where production breaks</li><li>Idempotency matters — Flows should be safe to re-run</li><li>Partial failures will happen — Plan for them with proper error handling</li><li>Use OData queries to verify state — Don’t trust reports during debugging</li><li>Flow run history is your friend — Learn to read inputs/outputs/errors</li><li>Alert on failures immediately — Don’t let broken terminations go unnoticed</li><li>Document remediation steps — Future-you (or your on-call colleague) will thank you</li></ul><p>—</p><h3>Summary of the Complete Series</h3><h4>Part 1: Understanding the HCM Data Model</h4><p>- D365 F&amp;O uses 6 entities to model employees</p><p>- OData v4 exposes these via REST APIs</p><p>- Power Automate wraps OData with connector actions</p><p>- `PartyNumber` is the foundation that ties everything together</p><h4>Part 2: Building the Termination Workflow</h4><p>- 5 entities must be updated in a specific order</p><p>- Use `runAfter` to enforce sequencing</p><p>- ETags prevent race conditions</p><p>- Explicit error handling is mandatory</p><h4>Part 3: Testing, Debugging, and Production Operations</h4><p>- Test edge cases, not just the golden path</p><p>- Debug with OData queries, not reports</p><p>- Read flow run history to find root causes</p><p>- Alert on failures and monitor data quality</p><p>—</p><h4>Final Thoughts</h4><p>If you have read the entire series, thanks a ton! Building production-grade integrations with D365 F&amp;O is not trivial. The HCM data model is sophisticated, the OData API has nuances, and Power Automate has its own quirks. I hope this series has helped!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1899a3559d8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/people-analytics-hris/designing-robust-employee-lifecycle-integrations-with-d365-f-o-1899a3559d8e">Designing Robust Employee Lifecycle Integrations with D365 F&amp;O Pt 3</a> was originally published in <a href="https://medium.com/people-analytics-hris">People Analytics &amp; HRIS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Robust Employee Lifecycle Integrations with D365 F&O Pt 2]]></title>
            <link>https://medium.com/people-analytics-hris/designing-robust-employee-lifecycle-integrations-with-d365-f-o-fa3ef33fbeb5?source=rss----5ccbf6d66090---4</link>
            <guid isPermaLink="false">https://medium.com/p/fa3ef33fbeb5</guid>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[dynamics-365]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[people-analytics]]></category>
            <category><![CDATA[microsoft]]></category>
            <dc:creator><![CDATA[Jesse Ruiz (she/they)]]></dc:creator>
            <pubDate>Sat, 31 Jan 2026 16:42:01 GMT</pubDate>
            <atom:updated>2026-01-31T16:42:00.196Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 2: Building the Termination Workflow</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BcYuC3I12mPo5vVc0rcWFw.png" /></figure><p>In this series of articles, I discuss a data integration project involving Dynamics 365 Finance and Operations and ADP. This project required orchestrating disparate HR systems to stay in sync with one another using OData integration and Power Automate.</p><p>This second article focuses on entity semantics, sequencing, and Power Automate implementation.</p><h4>What We’re Building</h4><p>In Part 1, we learned that D365 F&amp;O models employees across 6 entities. Now we’ll design the termination workflow that updates 5 of them (leaving People/Party intact for rehire scenarios).</p><p>The workflow must:</p><p>1. Set termination dates on the Employee contract</p><p>2. Mark the Worker as terminated and close validity windows</p><p>3. Free up the Position for reassignment</p><p>4. Close the Position Hierarchy reporting relationship</p><p>5. End the Position Worker Assignment link</p><p>Critical constraint: These updates must happen in a specific order, or you’ll create inconsistent data states.</p><p>—</p><h4>Entity 1: Employees — The Employment Contract</h4><p>The `Employees` entity represents the legal employment contract. When terminating, you’re closing this contract with specific dates and a reason code.</p><h4>The Payload</h4><pre>{<br>  &quot;TerminationDate&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;EmploymentEndDate&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;LastDateWorked&quot;: &quot;2024-12-30T00:00:00Z&quot;,<br>  &quot;TerminationReasonCodeId&quot;: &quot;RESIGN&quot;<br>}</pre><h4>Understanding Each Field</h4><p><strong>TerminationDate</strong>: When the employment relationship legally ends</p><p>- Used for benefits eligibility cutoff</p><p>- Determines final payroll period</p><p>- Must be &gt;= LastDateWorked</p><p><strong>EmploymentEndDate</strong>: Contract end date for legal/HR reporting</p><p>- Often same as TerminationDate</p><p>- Used for employment verification letters</p><p>- Required for compliance reporting</p><p><strong>LastDateWorked</strong>: Actual final workday</p><p>- Used for PTO accrual calculations</p><p>- Determines final timesheet period</p><p>- Typically 1 business day before TerminationDate</p><p><strong>TerminationReasonCodeId</strong>: Reason code (e.g., “RESIGN”, “TERMED”, “RETIRE”)</p><p>- Must match a valid code in D365 F&amp;O</p><p>- Used for exit interview tracking and reporting</p><p>- Affects rehire eligibility flags</p><h4>Power Automate Action</h4><pre>{<br>  &quot;name&quot;: &quot;Update_Employees&quot;,<br>  &quot;type&quot;: &quot;ApiConnection&quot;,<br>  &quot;inputs&quot;: {<br>    &quot;host&quot;: {<br>      &quot;connectionReferenceName&quot;: &quot;shared_dynamicsax&quot;,<br>      &quot;operationId&quot;: &quot;PatchItem&quot;<br>    },<br>    &quot;parameters&quot;: {<br>      &quot;dataset&quot;: &quot;instancename.operations.dynamics.com&quot;,<br>      &quot;table&quot;: &quot;Employees&quot;,<br>      &quot;id&quot;: &quot;PartyNumber=&#39;@{variables(&#39;PartyNumber&#39;)}&#39;,EmploymentLegalEntityId=&#39;ABCD&#39;&quot;,<br>      &quot;item/TerminationDate&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>      &quot;item/EmploymentEndDate&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>      &quot;item/LastDateWorked&quot;: &quot;2024-12-30T00:00:00Z&quot;,<br>      &quot;item/TerminationReasonCodeId&quot;: &quot;RESIGN&quot;<br>    }<br>  }<br>}</pre><p>Key detail: The `id` parameter uses a composite key because Employees requires both PartyNumber AND EmploymentLegalEntityId.</p><h4>Entity 2: Workers — The HR System Record</h4><p>The `Workers` entity is the HR-facing employee profile. You’re marking the worker as terminated and closing all validity windows.</p><h4>The Payload</h4><pre>{<br>  &quot;PersonDetailsValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;SummaryValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;PersonUserValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;WorkerStatus&quot;: &quot;Terminated&quot;<br>}</pre><h4>Understanding Each Field</h4><p><strong>PersonDetailsValidTo</strong>: Closes the personal information validity window</p><p>- When this worker’s demographic data is no longer “current”</p><p>- Still readable historically, just not “active”</p><p><strong>SummaryValidTo</strong>: Closes the employment summary validity window</p><p>- High-level employment status period</p><p>- Used by dashboards and reports to filter “current employees”</p><p><strong>PersonUserValidTo</strong>: Closes the user account linkage</p><p>- Can be used to trigger user deprovisioning in other systems</p><p>- Separates “person” from “system access”</p><p><strong>WorkerStatus</strong>: Enum value (“Active” → “Terminated”)</p><p>- Stored as integer internally (0=Active, 1=Terminated)</p><p>- Primary filter in most HR queries</p><p>- Triggers workflow rules in D365</p><h4>Power Automate Action</h4><pre>{<br>  &quot;name&quot;: &quot;Update_Workers&quot;,<br>  &quot;type&quot;: &quot;ApiConnection&quot;,<br>  &quot;inputs&quot;: {<br>    &quot;host&quot;: {<br>      &quot;connectionReferenceName&quot;: &quot;shared_dynamicsax&quot;,<br>      &quot;operationId&quot;: &quot;PatchItem&quot;<br>    },<br>    &quot;parameters&quot;: {<br>      &quot;dataset&quot;: &quot;instancename.operations.dynamics.com&quot;,<br>      &quot;table&quot;: &quot;Workers&quot;,<br>      &quot;id&quot;: &quot;PersonnelNumber=&#39;@{variables(&#39;PersonnelNumber&#39;)}&#39;&quot;,<br>      &quot;item/PersonDetailsValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>      &quot;item/SummaryValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>      &quot;item/PersonUserValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>      &quot;item/WorkerStatus&quot;: &quot;Terminated&quot;<br>    }<br>  },<br>  &quot;runAfter&quot;: {<br>    &quot;Update_Employees&quot;: [&quot;Succeeded&quot;]<br>  }<br>}</pre><p>Critical: Notice `runAfter` — this action only runs if `Update_Employees` succeeded.</p><h4>Entity 3: Positions — The Job Slots</h4><p>Positions represent the role, not the person. When terminating, you’re freeing up the position so it can be filled by someone else.</p><h4>The Payload</h4><pre>{<br>  &quot;WorkerAssignmentEnd&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;DetailExpiration&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;PayrollDetailExpiration&quot;: &quot;2024-12-31T23:59:59Z&quot;,<br>  &quot;AvailableForAssignment&quot;: &quot;Yes&quot;<br>}</pre><h4>Understanding Each Field</h4><p><strong>WorkerAssignmentEnd</strong>: When the current worker’s assignment to this position ends</p><p><strong>DetailExpiration</strong>: When this position configuration expires (if retiring the position)</p><p>- Set to termination date if position continues to exist</p><p>- Used for position budget lifecycle</p><p><strong>PayrollDetailExpiration</strong>: When payroll processing should stop for this position assignment</p><p><strong>AvailableForAssignment</strong>: Boolean flag indicating position can be filled</p><p>- “Yes” = position is vacant and recruitable</p><p>- “No” = position is on hold or being eliminated</p><h4>Entity 4 &amp; 5: PositionHierarchies and PositionWorkerAssignments</h4><h4>PositionHierarchies Payload</h4><pre>{<br>  &quot;ValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;<br>}</pre><p>Closes the reporting relationship edge in the org chart graph.</p><h4>PositionWorkerAssignments Payload</h4><pre>{<br>  &quot;ValidTo&quot;: &quot;2024-12-31T23:59:59Z&quot;<br>}</pre><p>Ends the concrete worker-to-position assignment.</p><h4>Why Sequence Matters: The Dependency Chain</h4><p>The Correct Order</p><p>1. Employees ← Set contract end dates</p><p>↓</p><p>2. Workers ← Mark as terminated</p><p>↓</p><p>3. Positions ← Free the job slot</p><p>↓</p><p>4. Hierarchies ← Close org chart edges</p><p>↓</p><p>5. Assignments ← End the linkage</p><h4>What Breaks If You Get It Wrong</h4><p><strong>Scenario 1: Update Workers before Employees</strong></p><blockquote>Worker status = “Terminated”</blockquote><blockquote>Employee TerminationDate = 2154–12–31 (still “active”)</blockquote><p>Result:</p><p>- Payroll report shows contradictory data</p><p>- Benefits system sees active contract, doesn’t terminate coverage</p><p>- Compliance reports fail validation</p><p><strong>Scenario 2: Free Position before updating Worker</strong></p><blockquote>Position.AvailableForAssignment = “Yes”</blockquote><blockquote>Worker status = “Active”</blockquote><blockquote>Assignment still links them</blockquote><p>Result:</p><p>- Recruiting tries to fill an “occupied” position</p><p>- Position shows in multiple org chart branches</p><p>- Budget allocation reports double-count</p><h4>The Real-World Impact</h4><p>A major retail client got this wrong and ended up with:</p><p>- 150+ positions showing as both “vacant” and “occupied”</p><p>- $2M in payroll continuation for terminated employees</p><p>- Failed SOX audit due to access control inconsistencies</p><p>The fix: Enforce strict ordering with Power Automate’s `runAfter` configuration.</p><h4>Implementing Sequential Execution in Power Automate</h4><p>The “Run After” Pattern</p><p>Power Automate actions have a `runAfter` property that controls execution dependencies:</p><pre>{<br>  &quot;Update_Workers&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Update_Employees&quot;: [&quot;Succeeded&quot;]<br>    },<br>    &quot;type&quot;: &quot;ApiConnection&quot;,<br>    &quot;inputs&quot;: { ... }<br>  }<br>}</pre><p>This means: “Only run Update_Workers if Update_Employees completed successfully.”</p><h4>The Complete Dependency Graph</h4><pre>{<br>  &quot;Update_Employees&quot;: {<br>    &quot;runAfter&quot;: {},<br>    &quot;type&quot;: &quot;ApiConnection&quot;<br>  },<br>  &quot;Update_Workers&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Update_Employees&quot;: [&quot;Succeeded&quot;]<br>    },<br>    &quot;type&quot;: &quot;ApiConnection&quot;<br>  },<br>  &quot;Update_Positions&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Update_Workers&quot;: [&quot;Succeeded&quot;]<br>    },<br>    &quot;type&quot;: &quot;ApiConnection&quot;<br>  },<br>  &quot;Check_Hierarchy_Exists&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Update_Positions&quot;: [&quot;Succeeded&quot;]<br>    },<br>    &quot;type&quot;: &quot;Condition&quot;<br>  },<br>  &quot;Update_PositionHierarchies&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Check_Hierarchy_Exists&quot;: [&quot;Succeeded&quot;]<br>    },<br>    &quot;type&quot;: &quot;ApiConnection&quot;<br>  },<br>  &quot;Update_PositionWorkerAssignments&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Update_PositionHierarchies&quot;: [&quot;Succeeded&quot;, &quot;Skipped&quot;]<br>    },<br>    &quot;type&quot;: &quot;ApiConnection&quot;<br>  }<br>}</pre><p>Note: `Update_PositionWorkerAssignments` runs after hierarchy update succeeds OR is skipped (for employees with no hierarchy node).</p><h4>Understanding @odata.etag and Concurrency Control</h4><p>The Problem: Race Conditions</p><p>Consider this scenario:</p><blockquote>Time Process A (Your flow) Process B (Manual update)</blockquote><blockquote>10:00 GET Employee (etag: “v1”)</blockquote><blockquote>10:01 GET Employee (etag: “v1”)</blockquote><blockquote>10:02 PATCH Employee → status=”On Leave”</blockquote><blockquote>10:03 New etag: “v2”</blockquote><blockquote>10:04 PATCH Employee → Terminate</blockquote><blockquote>(still using etag: “v1”)</blockquote><p>Without etag checking: Process A overwrites Process B’s change. The “On Leave” status disappears.</p><p>With etag checking: Process A’s PATCH fails with HTTP 412 Precondition Failed.</p><h4>How OData Uses ETags</h4><p>Every response includes an `@odata.etag` header:</p><pre>{<br>&quot;@odata.etag&quot;: &quot;W/\&quot;JzEsNTYzNzg0NzMyNzswLDAn\&quot;&quot;,<br>&quot;PartyNumber&quot;: &quot;000144139&quot;,<br>…<br>}</pre><p>When you PATCH, include the etag in the `If-Match` header:</p><pre>PATCH /data/Employees(…)<br>If-Match: W/&quot;JzEsNTYzNzg0NzMyNzswLDAn&quot;<br>{ &quot;TerminationDate&quot;: &quot;2024–12–31&quot; }</pre><p>If the etag doesn’t match, the server returns 412, preventing the overwrite.</p><h4>Power Automate Handling</h4><p>The Dynamics 365 F&amp;O connector automatically handles etags for most operations. But in high-concurrency scenarios:</p><p>1. Minimize time between GET and PATCH</p><p>2. Handle 412 errors gracefully (retry with fresh GET)</p><p>3. Don’t batch multiple updates to the same record without refreshing</p><p>Error Handling: Making Failures Visible</p><p><strong><em>The Silent Failure Problem</em></strong></p><p>Default Power Automate behavior:</p><p>- Action fails</p><p>- Flow shows “Failed” status</p><p>- No notification sent</p><p>- Employee still shows as active in reports</p><p>Result: The termination is incomplete, but nobody knows for days/weeks.</p><h4>The Solution: Explicit Error Handling</h4><pre>{<br>  &quot;Send_Error_Email&quot;: {<br>    &quot;runAfter&quot;: {<br>      &quot;Update_Employees&quot;: [&quot;Failed&quot;, &quot;TimedOut&quot;],<br>      &quot;Update_Workers&quot;: [&quot;Failed&quot;, &quot;TimedOut&quot;],<br>      &quot;Update_Positions&quot;: [&quot;Failed&quot;, &quot;TimedOut&quot;]<br>    },<br>    &quot;type&quot;: &quot;ApiConnection&quot;,<br>    &quot;inputs&quot;: {<br>      &quot;host&quot;: {<br>        &quot;connectionReferenceName&quot;: &quot;shared_office365&quot;,<br>        &quot;operationId&quot;: &quot;SendEmailV2&quot;<br>      },<br>      &quot;parameters&quot;: {<br>        &quot;emailMessage/To&quot;: &quot;hr-integrations@company.com&quot;,<br>        &quot;emailMessage/Subject&quot;: &quot;Termination Failed: @{variables(&#39;PersonnelNumber&#39;)}&quot;,<br>        &quot;emailMessage/Body&quot;: &quot;&lt;p&gt;Action failed: @{actions(&#39;Update_Workers&#39;)?[&#39;status&#39;]}&lt;/p&gt;&lt;p&gt;Error: @{body(&#39;Update_Workers&#39;)?[&#39;error&#39;]?[&#39;message&#39;]}&lt;/p&gt;&quot;<br>      }<br>    }<br>  }<br>}</pre><p>What to Include in Error Notifications</p><p>1. PersonnelNumber — so you know which termination failed</p><p>2. Failed action name — which entity update broke</p><p>3. HTTP status code — 400 (bad request), 404 (not found), 412 (etag conflict), 500 (server error)</p><p>4. Error message — OData error details</p><p>5. Flow run URL — direct link for debugging</p><h4>Key Takeaways from Part 2</h4><ul><li>Five entities require updates during termination (People/Party is left intact)</li><li>Order is critical — Employee → Worker → Position → Hierarchy → Assignment</li><li>Use runAfter in Power Automate to enforce sequencing</li><li>ETags prevent race conditions — the connector handles this automatically in most cases</li><li>Explicit error handling is mandatory — don’t let failures go silent</li><li>Each entity has different semantics — understand what you’re changing and why</li></ul><p>—</p><h4>Coming in Part 3</h4><p>Testing, Debugging, and Operating in Production</p><p>- Building a comprehensive test suite (golden path, edge cases, idempotency)</p><p>- Debugging production failures with raw OData queries</p><p>- Reading flow run history to diagnose issues</p><p>- Alerting patterns for different failure modes</p><p>—</p><p>Continue to Part 3: Testing &amp; Debugging →</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa3ef33fbeb5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/people-analytics-hris/designing-robust-employee-lifecycle-integrations-with-d365-f-o-fa3ef33fbeb5">Designing Robust Employee Lifecycle Integrations with D365 F&amp;O Pt 2</a> was originally published in <a href="https://medium.com/people-analytics-hris">People Analytics &amp; HRIS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Robust Employee Lifecycle Integrations with D365 F&O Pt 1]]></title>
            <link>https://medium.com/people-analytics-hris/designing-robust-employee-lifecycle-integrations-with-d365-f-o-8323965ef4e7?source=rss----5ccbf6d66090---4</link>
            <guid isPermaLink="false">https://medium.com/p/8323965ef4e7</guid>
            <category><![CDATA[dynamics-365]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-pipeline]]></category>
            <category><![CDATA[microsoft]]></category>
            <dc:creator><![CDATA[Jesse Ruiz (she/they)]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 17:17:44 GMT</pubDate>
            <atom:updated>2026-01-25T21:04:52.079Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1: Understanding the HCM Data Model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OIY0idfs_i2Qd7dvdGKVNg.png" /></figure><p>In this series of articles, I discuss a data integration project involving Dynamics 365 Finance and Operations and ADP. This project required orchestrating disparate HR systems to stay in sync with one another using OData integration and Power Automate.</p><p>This first article focuses on understanding the underlying target data model in order to begin to building production-grade employee termination workflows.</p><h4>The Challenge: Why Employee Termination Isn’t Just Flipping a Boolean</h4><p>If you’ve ever worked with a typical CRUD application, you might expect employee termination to look something like this:</p><pre>- basic crud:<br>UPDATE Employees<br>SET IsActive = 0, TerminatedDate = GETDATE()<br>WHERE EmployeeID = &#39;126845&#39;;<br>```</pre><p>In Dynamics 365 Finance &amp; Operations (D365 F&amp;O), this is not remotely how it works. Given that D365 is one of the oldest ERP’s in the books, the data model is highly structured and standardized in addition to being capable of customizations.</p><p>Terminating an employee in D365 F&amp;O requires coordinated updates across at least 6 different entities, each with their own validity windows, status fields, and referential constraints. Miss one, and you end up with:</p><p>- Employees who show as “terminated” in HR reports but still appear “active” in payroll</p><p>- Positions that remain assigned to departed workers, blocking new hires</p><p>- Org charts with dangling references to people who left months ago</p><p>- Compliance audit failures because employment end dates don’t match across systems</p><p>This isn’t bad design — it’s <em>sophisticated temporal modeling</em> that supports complex real-world HR scenarios like:</p><p>- Rehires: The same person (party) can be employed multiple times with different contracts</p><p>- Multiple positions: An employee can hold several positions simultaneously (e.g., manager + interim director)</p><p>-Historical reporting: “Who reported to whom on December 31, 2023?” must be answerable years later</p><p>- Legal compliance: Different employment aspects (contract end, last day worked, benefits eligibility) have different legal definitions and dates</p><p>This three-part series walks through building a production-grade termination workflow using D365 F&amp;O’s OData API and Power Automate. This first article focuses on understanding the data model you’re actually integrating with.</p><h4>Who This Is For</h4><p>This guide assumes you:</p><p>- Understand REST APIs: You know what HTTP verbs (GET, POST, PATCH) do and how JSON works</p><p>- Have used Power Automate: You’ve built flows and understand connectors and actions</p><p>- Need production-grade reliability: You’re not building a demo — real people’s paychecks depend on this</p><p>- Want to understand the “why”: You’re not just copying code; you want to know why the integration is designed this way</p><h4>What we won’t cover:</h4><p>- Basic Power Automate tutorials (there are plenty of those)</p><p>- Business justifications for using D365 F&amp;O (you’re already here)</p><p>- Alternative approaches like X++ or batch jobs (this is specifically about OData + Power Automate)</p><h4>The HCM Data Model</h4><h4>The Six Core Entities</h4><p>At minimum, you must understand these entities and how they relate:</p><p><strong>1. People (Party)</strong></p><p>The global person record — name, addresses, contact information</p><p>Key identifier: `PartyNumber` (e.g., “000199189”)</p><p>Lifespan: Permanent — persists across employment periods, even after termination</p><p>Think of it as: The “natural person” in legal terms</p><p>Why it’s separate from employment: A person might be hired, terminated, then rehired years later. The same party record is reused. This enables:</p><ul><li>Historical continuity (“John Smith worked here from 2015–2017 and was rehired in 2023”)</li><li>Consolidated contact information across roles</li><li>Compliance with “right to be forgotten” regulations (you can mark the party inactive without destroying employment history)</li></ul><p><strong>2. Workers</strong></p><p>The HR system record that ties a party to employment</p><p>Key identifier: `PersonnelNumber` (e.g., “199199”) — this is the “employee ID” users see</p><p>Relationship: `Workers.PartyNumber` → `People.PartyNumber` (one-to-one during active employment)</p><p>Contains: Employment-related metadata, validity periods, worker status</p><p>Think of it as: The “employee profile”</p><p>Why it’s separate: Workers can have different personnel numbers across different legal entities or employment periods. The same person (party “000199189”) might be:</p><ul><li>Personnel number “100523” in their first employment period (2015–2017)</li><li>Personnel number “104829” when rehired (2023-present)</li></ul><p><strong>3. Employees</strong></p><p>The employment contract — start date, end date, termination reason, employment type</p><p>Key identifiers: `PartyNumber` + `EmploymentLegalEntityId` (composite key)</p><p>Relationship: One worker can have multiple employee records (one per legal entity)</p><p>Contains: `EmploymentStartDate`, `EmploymentEndDate`, `TerminationDate`, `LastDateWorked`, `TerminationReasonCodeId`</p><p>Think of it as: The “employment contract”</p><p>The crucial detail: `TerminationDate` and `EmploymentEndDate` are not interchangeable:</p><blockquote>Scenario: Employee resigns with 2 weeks notice</blockquote><blockquote>- LastDateWorked: Dec 20, 2024 (Friday, their last physical workday)</blockquote><blockquote>- TerminationDate: Dec 31, 2024 (End of pay period, benefits cutoff)</blockquote><blockquote>- EmploymentEndDate: Dec 31, 2024 (Legal contract end date)</blockquote><p>Why three dates?</p><ul><li>Payroll needs LastDateWorked for PTO accrual calculations</li><li>Benefits eligibility ends on TerminationDate</li><li>Legal reporting uses EmploymentEndDate for employment verification</li></ul><p>If you set them all to the same date “because it’s simpler,” you might accidentally:</p><ul><li>Stop benefits eligibility before the person’s last day</li><li>Miscalculate PTO payouts</li><li>Generate incorrect employment verification letters</li></ul><p><strong>4. Positions</strong></p><p>A job slot in the organization — not the person, the role itself</p><p>Key identifier: `PositionId` (e.g., “POS-0001234”)</p><p>Contains: Job title, department, reporting manager position, FTE, budget codes</p><p>Lifespan: Exists independently of whether anyone fills it</p><p>Think of it as: The “chair” that people sit in</p><p>Why positions exist separately from employees:</p><blockquote>Position: “Senior Data Engineer — Analytics Team”</blockquote><blockquote>- Created: Jan 2023</blockquote><blockquote>- Budgeted headcount: 1.0 FTE</blockquote><blockquote>- Reports to: “Director of Data Engineering” (another position)</blockquote><blockquote>Occupancy history:</blockquote><blockquote>- 2023–01–15 to 2024–06–30: Alice Johnson (personnel 100234)</blockquote><blockquote>- 2024–06–30 to 2024–08–15: [vacant]</blockquote><blockquote>- 2024–08–16 to present: Bob Chen (personnel 102456)</blockquote><p>This allows:</p><ul><li>Budget planning independent of current staff</li><li>Posting job openings for unfilled positions</li><li>Historical reporting (“Who held this position in Q2 2023?”)</li><li>Org structure stability even during turnover</li></ul><p><strong>5. PositionHierarchies</strong></p><p>The reporting structure — which positions report to which other positions</p><p>Key fields: `ChildPositionId`, `ParentPositionId`, `ValidFrom`, `ValidTo`, `HierarchyTypeId`</p><p>Contains: The edges in the org chart graph</p><p>Think of it as: The lines connecting boxes on an org chart</p><p>Why this is time-bounded:</p><blockquote>Scenario: Org restructuring</blockquote><blockquote>Position “Senior Engineer” (POS-123):</blockquote><blockquote>- Jan-Jun 2024: Reports to “Manager A” (POS-456)</blockquote><blockquote>HierarchyRecord: ChildPosition=123, ParentPosition=456,</blockquote><blockquote>ValidFrom=2024–01–01, ValidTo=2024–06–30</blockquote><blockquote>- Jul-Dec 2024: Reports to “Manager B” (POS-789)</blockquote><blockquote>HierarchyRecord: ChildPosition=123, ParentPosition=789,</blockquote><blockquote>ValidFrom=2024–07–01, ValidTo=2154–12–31</blockquote><p>Queries like “Who reported to Manager A in March 2024?” must still return correct results years later for compliance and historical analysis.</p><p><strong>6. PositionWorkerAssignments</strong></p><p>The concrete link — which worker is assigned to which position, and when</p><p>Key fields: `PositionId`, `PersonnelNumber`, `ValidFrom`, `ValidTo`</p><p>Contains: Assignment type, FTE percentage, assignment reason</p><p>Think of it as: The “seating chart”</p><p>Why this is separate from Position:</p><blockquote>A single worker can hold multiple positions simultaneously:</blockquote><blockquote>Worker: Alice Johnson (personnel 100234)</blockquote><blockquote>Assignments (all active on Nov 1, 2024):</blockquote><blockquote>1. Position: “Senior Engineer” (POS-123)</blockquote><blockquote>- ValidFrom: 2022–01–01</blockquote><blockquote>- ValidTo: 2154–12–31</blockquote><blockquote>- FTE: 0.8 (80%)</blockquote><blockquote>2. Position: “Interim Team Lead” (POS-456)</blockquote><blockquote>- ValidFrom: 2024–09–01</blockquote><blockquote>- ValidTo: 2024–12–31</blockquote><blockquote>- FTE: 0.2 (20%)</blockquote><blockquote>Total FTE: 1.0 (100% capacity)</blockquote><p>When Alice is terminated, both assignments must be closed, or one position will remain “occupied” by a terminated employee.</p><h3>The Entity Relationship</h3><p>Here’s the simplified relationship structure (arrows show foreign key direction):</p><p>People (PartyNumber: “000199189”)</p><p>↓</p><p>Workers (PersonnelNumber: “199199”, PartyNumber: “000199189”)</p><p>↓</p><p>├→ Employees (PartyNumber: “000199189”, LegalEntity: “USMF”)</p><p>│</p><p>└→ PositionWorkerAssignments (PersonnelNumber: “199199”, PositionId: “POS-123”)</p><p>↓</p><p>Positions (PositionId: “POS-123”)</p><p>↓</p><p>PositionHierarchies (ChildPositionId: “POS-123”, ParentPositionId: “POS-456”)</p><p>Key takeaway: To terminate an employee, you’re not updating one record. You’re closing validity windows across 5 entities while leaving the 6th (People/Party) intact for future rehire.</p><h4>How D365 F&amp;O Exposes This via OData</h4><h4>OData v4 Basics</h4><p>D365 F&amp;O exposes its data model as an OData v4 service:</p><p>Service root:</p><p><a href="https://{instance}.operations.dynamics.com/data/">https://{instance}.operations.dynamics.com/data/</a></p><p>Metadata (the schema definition):</p><p><a href="https://{instance}.operations.dynamics.com/data/$metadata">https://{instance}.operations.dynamics.com/data/$metadata</a></p><p>Entity sets (the “tables” you interact with):</p><p><a href="https://{instance}.operations.dynamics.com/data/People">https://{instance}.operations.dynamics.com/data/People</a></p><p><a href="https://{instance}.operations.dynamics.com/data/Workers">https://{instance}.operations.dynamics.com/data/Workers</a></p><p><a href="https://{instance}.operations.dynamics.com/data/Employees">https://{instance}.operations.dynamics.com/data/Employees</a></p><p>Each entity set supports standard OData operations:</p><p><strong>| Operation | HTTP Verb | Example | Purpose |</strong></p><p><strong>| — — — — — -| — — — — — -| — — — — -| — — — — — |</strong></p><p><strong>| Query | GET | `GET /data/Workers?$filter=PersonnelNumber eq ‘199199’` | Find records |</strong></p><p><strong>| Create | POST | `POST /data/People` with JSON body | Create new record |</strong></p><p><strong>| Update | PATCH | `PATCH /data/Employees(PartyNumber=’000199199&#39;,…)` | Modify existing record |</strong></p><p><strong>| Delete | DELETE | `DELETE /data/Workers(…)` | Remove record (rare in HR) |</strong></p><h4>OData Query Capabilities You’ll Need</h4><p><strong>1. Filtering</strong></p><pre>GET /data/Workers?$filter=PersonnelNumber eq &#39;199199&#39;</pre><p>Used to resolve business identifiers (personnel numbers) to system keys (party numbers).</p><p><strong>2. Expansion (following relationships)</strong></p><pre>GET /data/Workers?$expand=Employment,Positions&amp;$filter=PersonnelNumber eq &#39;199199&#39;</pre><p>Returns the worker plus related employment and position data in one call.</p><p><strong>3. Selection (projection)</strong></p><pre>GET /data/Workers?$select=PartyNumber,PersonnelNumber,WorkerStatus</pre><p>Limits returned fields to reduce payload size.</p><p><strong>4. Composite Keys (for entities with multi-part keys)</strong></p><pre>PATCH /data/Employees(PartyNumber=&#39;000199189&#39;,EmploymentLegalEntityId=&#39;USMF&#39;,…)</pre><p>Employees require both `PartyNumber` AND `EmploymentLegalEntityId` to uniquely identify a record.</p><p>—</p><h3>How Power Automate Wraps OData</h3><h4>The Dynamics 365 Finance and Operations Connector</h4><p>Power Automate provides the Dynamics 365 Finance and Operations connector, which abstracts the HTTP calls into actions:</p><p>Connector Actions Map to OData Operations:</p><p>| Power Automate Action | OData Operation | HTTP Example |</p><p>| — — — — — — — — — — — | — — — — — — — — -| — — — — — — -|</p><p>| Create record | POST to entity set | `POST /data/People` |</p><p>| Update record | PATCH to entity instance | `PATCH /data/Employees(…)` |</p><p>| Get record | GET entity instance | `GET /data/Workers(…)` |</p><p>| List records | GET entity set with $filter | `GET /data/Workers?$filter=…` |</p><p>| Execute action | POST to bound/unbound action | `POST /data/Workers/Microsoft.Dynamics.DataEntities.Terminate` |</p><p>Under the hood, when you use “Create record” in Power Automate, it’s generating an HTTP request like:</p><pre>POST https://instancename.operations.dynamics.com/data/People HTTP/1.1<br>Content-Type: application/json<br>Authorization: Bearer {token}<br>{<br>&quot;FirstName&quot;: &quot;John&quot;,<br>&quot;LastName&quot;: &quot;Smith&quot;,<br>&quot;NameSequenceDisplayAs&quot;: &quot;LastCommaFirstMiddle&quot;,<br>&quot;AddressBooks&quot;: &quot;1999&quot;,<br>&quot;AddressValidFrom&quot;: &quot;2024–12–02T00:00:00Z&quot;,<br>&quot;AddressValidTo&quot;: &quot;2154–12–31T23:59:59Z&quot;<br>}</pre><p>The connector handles:</p><ul><li>Authentication (OAuth bearer tokens)</li><li>Header construction</li><li>JSON serialization</li><li>Response parsing</li><li>Error handling</li></ul><p>But you still need to understand what the underlying OData call is doing, because:</p><p>1. Debugging: When things fail, you need to read the OData error messages</p><p>2. Performance: Understanding when you’re making multiple round-trips vs. one $expand query</p><p>3. Correctness: Knowing which fields are required vs. optional</p><p>—</p><h3>Creating a Person</h3><p>In the context of the project requirements, original employees were created once a person was officially hired. At that point in time, the person was migrated from ADP to D365. So therefore, it was necessary to create a person as an employee within D365. So within D365, every new employee lifecycle begins with creating a Person (Party) record. This generates the `PartyNumber`, which is the primary key that ties together:</p><ul><li>Workers (via `Workers.PartyNumber`)</li><li>Employees (via `Employees.PartyNumber`)</li><li>All downstream HR data</li></ul><p>Without a valid `PartyNumber`, you can’t create a Worker. Without a Worker, you can’t create position assignments. The entire entity graph depends on this foundation.</p><h4>Anatomy of a Person Creation in Power Automate</h4><p>Here’s what the Power Automate action looks like (simplified JSON definition):</p><pre>{<br>&quot;name&quot;: &quot;Create_record_People&quot;,<br>&quot;type&quot;: &quot;ApiConnection&quot;,<br>&quot;inputs&quot;: {<br>&quot;host&quot;: {<br>&quot;apiId&quot;: &quot;/subscriptions/2e6e5a0a…/providers/Microsoft.Web/locations/eastus/managedApis/dynamicsax&quot;,<br>&quot;connectionReferenceName&quot;: &quot;shared_dynamicsax&quot;,<br>&quot;operationId&quot;: &quot;PostItem&quot;<br>},<br>&quot;parameters&quot;: {<br>&quot;dataset&quot;: &quot;instancename.operations.dynamics.com&quot;,<br>&quot;table&quot;: &quot;People&quot;,<br>&quot;item/NameSequenceDisplayAs&quot;: &quot;LastCommaFirstMiddle&quot;,<br>&quot;item/LastName&quot;: &quot;Smith&quot;,<br>&quot;item/FirstName&quot;: &quot;John&quot;,<br>&quot;item/AddressBooks&quot;: &quot;1999&quot;,<br>&quot;item/AddressValidFrom&quot;: &quot;2024–01–02T00:00:00Z&quot;,<br>&quot;item/AddressValidTo&quot;: &quot;2154–12–31T23:59:59Z&quot;<br>}<br>},<br>&quot;outputs&quot;: {<br>&quot;statusCode&quot;: 201,<br>&quot;headers&quot;: {<br>&quot;Location&quot;: &quot;https://instancename.operations.dynamics.com/data/People(PartyNumber=&#39;000199189&#39;)&quot;<br>},<br>&quot;body&quot;: {<br>&quot;@odata.context&quot;: &quot;https://instancename.operations.dynamics.com/data/$metadata#People/$entity&quot;,<br>&quot;@odata.etag&quot;: &quot;W/\&quot;JzEsNTYzNzg0NzMyNzswLDAn\&quot;&quot;,<br>&quot;PartyNumber&quot;: &quot;000199189&quot;,<br>&quot;FirstName&quot;: &quot;John&quot;,<br>&quot;LastName&quot;: &quot;Smith&quot;<br>}<br>}<br>}</pre><h4>Understanding Each Component</h4><h4>1. Connection Metadata</h4><pre>&quot;host&quot;: {<br>&quot;apiId&quot;: &quot;/subscriptions/…/managedApis/dynamicsax&quot;,<br>&quot;connectionReferenceName&quot;: &quot;shared_dynamicsax&quot;,<br>&quot;operationId&quot;: &quot;PostItem&quot;<br>}</pre><p>- apiId: Identifies which Azure API Management-backed connector this is (D365 F&amp;O)</p><p>- connectionReferenceName: Points to your environment-specific connection (contains credentials)</p><p>- operationId: “PostItem”: This is the generic “POST to entity set” operation</p><h4>2. Target Entity</h4><pre>&quot;parameters&quot;: {<br>&quot;dataset&quot;: &quot;instancename.operations.dynamics.com&quot;,<br>&quot;table&quot;: &quot;People&quot;<br>}</pre><p>- dataset: Your D365 F&amp;O instance URL</p><p>- table: The OData entity set name — this resolves to `/data/People`</p><h4>3. Request Body (The Actual Data)</h4><p>The `item/` prefixes in Power Automate get stripped and sent as the JSON body:</p><pre>{<br>&quot;NameSequenceDisplayAs&quot;: &quot;LastCommaFirstMiddle&quot;,<br>&quot;LastName&quot;: &quot;Smith&quot;,<br>&quot;FirstName&quot;: &quot;John&quot;,<br>&quot;AddressBooks&quot;: &quot;1999&quot;,<br>&quot;AddressValidFrom&quot;: &quot;2024–12–02T00:00:00Z&quot;,<br>&quot;AddressValidTo&quot;: &quot;2154–12–31T23:59:59Z&quot;<br>}</pre><h4>Critical fields explained:</h4><p><strong>NameSequenceDisplayAs</strong>: Controls how the name appears in reports and UI</p><ul><li>`”LastCommaFirstMiddle”` → “Smith, John”</li><li>`”FirstMiddleLast”` → “John Smith”</li></ul><p>- This affects HR documents, so it’s crucial to get it right and keep it consistent.</p><p><strong>AddressBooks</strong>: The address book ID this party belongs to</p><ul><li>Value `”1999&quot;` might represent something different in your operational setup. In my case, it related to IT-specific permissions based on job title.</li></ul><p>If you omit this, the person might not show up in employee searches or reports. This is one of those “optional” fields that isn’t really optional.</p><p><strong>AddressValidFrom </strong>/ <strong>AddressValidTo</strong>: Time bounds for the address record</p><ul><li>`ValidFrom: “2024–12–02”` → when this person’s data becomes effective</li><li>`ValidTo: “2154–12–31T23:59:59Z”` → the “infinity” date in D365</li></ul><p><strong>Why 2154–12–31? </strong>This is Microsoft’s standard “no end date” convention. Don’t use:</p><ul><li>`9999–12–31` (some systems interpret this as an error)</li><li>`2099–12–31` (some queries treat this differently)</li><li>`NULL` (D365 doesn’t allow null for ValidTo in many entities)</li></ul><p>The date `2154–12–31` is baked into D365’s date logic and recognized by standard reports, batch jobs, and integrations.</p><h4>4. Response</h4><pre>&quot;outputs&quot;: {<br>&quot;statusCode&quot;: 201,<br>&quot;body&quot;: {<br>&quot;@odata.etag&quot;: &quot;W/\&quot;JzEvNTYcNzg0NzMyNzswLDAn\&quot;&quot;,<br>&quot;PartyNumber&quot;: &quot;000199189&quot;<br>}<br>}</pre><p>HTTP 201 Created: Success! The record was created.</p><p>@odata.etag: An opaque version identifier used for optimistic concurrency control (more on this in Part 2)</p><p>PartyNumber: “000199189”: THIS IS THE MOST IMPORTANT VALUE. You must:</p><p>1. Capture it immediately in a Power Automate variable</p><p>2. Use it to create the Worker record</p><p>3. Use it in all downstream Employee/Position operations</p><p>If you lose this `PartyNumber`, you’ve created an orphaned party record with no way to link it to employment data.</p><h4>Capturing the PartyNumber in Power Automate</h4><p>Immediately after the “Create record (People)” action, add these actions:</p><p>Action 1: Initialize variable — PartyNumber</p><pre>{<br>&quot;name&quot;: &quot;Initialize_PartyNumber&quot;,<br>&quot;type&quot;: &quot;InitializeVariable&quot;,<br>&quot;inputs&quot;: {<br>&quot;variables&quot;: [{<br>&quot;name&quot;: &quot;PartyNumber&quot;,<br>&quot;type&quot;: &quot;String&quot;,<br>&quot;value&quot;: &quot;@body(&#39;Create_record_People&#39;)?[&#39;PartyNumber&#39;]&quot;<br>}]<br>}<br>}</pre><p>Action 2: Initialize variable — PeopleEtag (optional but recommended)</p><pre>{<br>&quot;name&quot;: &quot;Initialize_PeopleEtag&quot;,<br>&quot;type&quot;: &quot;InitializeVariable&quot;,<br>&quot;inputs&quot;: {<br>&quot;variables&quot;: [{<br>&quot;name&quot;: &quot;PeopleEtag&quot;,<br>&quot;type&quot;: &quot;String&quot;,<br>&quot;value&quot;: &quot;@body(&#39;Create_record_People&#39;)?[&#39;@odata.etag&#39;]&quot;<br>}]<br>}<br>}</pre><p>The `?[‘PropertyName’]` syntax is the safe navigation operator — if the property doesn’t exist, it returns null instead of throwing an error.</p><h3>What We’ve Covered (And What’s Next)</h3><h4>Key Takeaways from Part 1</h4><ul><li>D365 F&amp;O HCM is a temporal, multi-entity graph, not a single “Employees” table</li><li>Six core entities work together: People → Workers → Employees → Positions → Hierarchies → Assignments</li><li>OData v4 is the REST API layer that exposes these entities</li><li>Power Automate’s connector wraps OData but you need to understand the underlying HTTP calls</li><li>Creating a Person generates the `PartyNumber`, which is the foundation for all employment data</li><li>Validity windows (`ValidFrom` / `ValidTo`) are how D365 models time — you’re not deleting records, you’re closing windows</li><li>The “infinity date” (2154–12–31) represents “no end date” in D365’s temporal model</li></ul><h4>Coming in Part 2</h4><p>Building the Termination Workflow: Entity Semantics and Sequencing</p><p>- Entity-specific termination payloads: What fields to set on Employees, Workers, Positions, Hierarchies, and Assignments</p><p>- Why order matters: The dependency chain and what breaks if you get it wrong</p><p>- Implementing sequential execution in Power Automate with “Run After” logic</p><p>- ETag and concurrency control: Avoiding race conditions and 412 errors</p><p>- Error handling patterns: Catching failures and making them visible</p><h4>Coming in Part 3</h4><p>Testing, Debugging, and Operating in Production</p><p>We’ll cover:</p><p>- Testing strategies: Golden path, edge cases, idempotency, and partial failure simulation</p><p>- Debugging production incidents: Using raw OData queries to diagnose termination failures</p><p>- Flow run history forensics: Reading HTTP status codes and error payloads</p><p>- Alerting patterns: Making sure failures don’t go silent</p><p>—</p><p>Continue to Part 2: Building the Termination Workflow →</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8323965ef4e7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/people-analytics-hris/designing-robust-employee-lifecycle-integrations-with-d365-f-o-8323965ef4e7">Designing Robust Employee Lifecycle Integrations with D365 F&amp;O Pt 1</a> was originally published in <a href="https://medium.com/people-analytics-hris">People Analytics &amp; HRIS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>