cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Darione78
Frequent Visitor

Dynamics "update a record" doesn't work with Employment tables in Dynamics 365 for operations

Hi,

 

I'm trying to update the employment end date for employees in Dynamics 365 FO from an excel file. I've tried with data entities Employees, Emploments, Employment details without any luck. I am setting the update in the following way, using field PersonnelNumber, LegalEntityId, EmploymentStartDate, 2154-12-31T23:59:59Z (as employmentEndDate), ValidFromDate, ValidToDate to define Object id, and obviously setting up Employment end date to a new end date.

 

Am I missing something?


Thank you,

Dario

 

Darione78_1-1606180175419.png

 

 

 

2 REPLIES 2
RolfEleveld
New Member

Hi Dario,
I am having a similar issue, where the update record requires employee type, so when I enter it

RolfEleveld_0-1620846797683.png

It returns an error stating an existing worker type cannot be updated. 
When using the export-edit JSON-import route (does not work with OpenApi), I can adapt the JSON to process only the fields that need to be updated:

"inputs": {
    "host": {
        "connection": {
            "name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_dynamicsax']['connectionId']"
        }
    },
    "method": "patch",
    "body": {
        "EmploymentEndDate": "2021-04-30T23:59:59Z",
        "TransitionDate": "2021-04-30T23:59:59Z",
        "LastDateWorked": "2021-04-18T23:59:59Z"
    },
    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('roelf_eleveld-demo-2.sandbox.operations.dynamics.com'))}/tables/@{encodeURIComponent(encodeURIComponent('EmploymentDetails'))}/items/@{encodeURIComponent(encodeURIComponent('000321,DAT,2001-01-01T00:00:00Z,2154-12-31T23:59:59Z,2018-01-01T12:03:38Z,2154-12-31T23:59:59Z'))}",
    "authentication": {
        "type": "Raw",
        "value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
    }
},
"metadata": {
    "flowSystemMetadata": {
        "swaggerOperationId": "PatchItem"
    }
}

This tells me that the record could not be found, when I remove the line:

"EmploymentEndDate": "2021-04-30T23:59:59Z",

I can import the flow and run it with success, but that does not update the end date so the employee gets terminated in the system and goes out of scope. The other fields I have in the update do get populated correctly this way. Whenever I have the above field in the EmployeeDetails update it fails. Would be great to see feedback from another Power Automate user!

RolfEleveld
New Member

TLDR: use the Entity EmploymentsPerCompany
At the moment I finished the previous entry I realized perhaps the not found message is a message that comes from an internal issue in the API, not the object itself. so I browsed through all HR related OData objects /data/ and found a difference between manually expired employees and the one I wished to expire but could not. long story short I was able to update the user with the following:

 

"metadata": {
    "flowSystemMetadata": {
        "swaggerOperationId": "PatchItem"
    }
},
"inputs": {
    "host": {
        "connection": {
            "name": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$connections']['shared_dynamicsax']['connectionId']"
        }
    },
    "method": "patch",
    "body": {
        "EmploymentEndDate": "2021-04-30T23:59:59Z"
    },
    "path": "/datasets/@{encodeURIComponent(encodeURIComponent('roelf_eleveld-demo-14.sandbox.operations.dynamics.com'))}/tables/@{encodeURIComponent(encodeURIComponent('EmploymentsPerCompany'))}/items/@{encodeURIComponent(encodeURIComponent('000321,DAT,2001-01-01T00:00:00Z'))}",
    "authentication": {
        "type": "Raw",
        "value": "@json(decodeBase64(triggerOutputs().headers['X-MS-APIM-Tokens']))['$ConnectionKey']"
    }
}

 

I hope this helps all of you and especially myself next time I wish to expire an employee from flow.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,001)