Find the current and previous user of a reassigned approval flow from the Common Data Service (CDS): Part 2

Share the love

My last post, Capturing a reassigned approval flow from the Common Data Service (CDS), detailed how you can find a reassigned approval request in the Common Data Service, however, I did not detail how you get the user details.

Last time, my flow triggered every time a new request was created in the CDS (which is the easiest way to capture reassigned flows). This post will pick up from there, or you can follow this post independently if you don’t want to trigger each time a new request is created.

To get the Approval Request that has been reassigned, list all the records from the Approval Requests entity and filter on the Approval ID and the Owner ID. In my action, the ApprovalRequest parameter is a value that is passed in from another flow (or it would be the ID of the request that triggered the flow if you’re following on from the last post). If you have this value already in your log, you can place this value here. The Owner ID is the GUID of the user with whom the approval flow has been reassigned to. If you’re following on from the last post, this is the value from the Reassigned From field (msdyn_flow_approvalrequestidx_reassignedfromid) in the Approval Request entity. If you’re creating this flow independently, it is quite possible you don’t have the Owner ID, so in this case, ordering by the msdyn_flow_approvalrequest_lastnotifiedon in descending order will be your best chance at finding the reassigned user.

I have used the current Owner ID in a previous action in this flow (Get record – Get response user which gets information from the Users entity) so I can pull additional information about the user later (however you do not need to do this). I have used the User ID parameter from the previous action in the query below.

msdyn_flow_approvalrequestidx_approvalid eq 'triggerBody()?['text_3']' and msdyn_flow_approvalrequestidx_owninguserid eq 'outputs('Get_record_-_Get_response_user')?['body/systemuserid']'

Even though we said to only return one result, we will still need to access the array of results. The value that we are after is msdyn_flow_approvalrequestidx_reassignedfromid. This is the ID of the user who reassigned the flow.

outputs('List_records_-_Get_current_request')?['body']?['value']?[0]?['msdyn_flow_approvalrequestidx_reassignedfromid']

Now we have the record of the reassigned flow, and the flow that was used to reassign to another user. In order to get the details of the user who reassigned the flow, we need to use the Users entity and pass in the Owner ID of the previous action (Get record – Get previous request).

outputs('Get_record_-_Get_previous_request')?['body/_ownerid_value']

Now that you’ve got the Users entity, this gives you access to the users email, phone numbers, addresses etc. We can use this information to update the workflow log with who the flow was originally assigned to, and who it is now assigned to. In my example, I have used JSON.

{
  "reassign": [
    {
      "responder": {
        "id": "outputs('Get_record_-_Get_previous_owner')?['body/systemuserid']",
        "displayName": "outputs('Get_record_-_Get_previous_owner')?['body/fullname']",
        "email": "outputs('Get_record_-_Get_previous_owner')?['body/internalemailaddress']"
      },
      "responseDate": "outputs('List_records_-_Get_current_request')?['body']?['value']?[0]?['modifiedon']",
      "approverResponse": "Reassigned"
    }
  ],
  "reassigned": [
    {
      "reassigned": {
        "id": "outputs('Get_record_-_Get_response_user')?['body/systemuserid']",
        "displayName": "outputs('Get_record_-_Get_response_user')?['body/fullname']",
        "email": "outputs('Get_record_-_Get_response_user')?['body/internalemailaddress']"
      }
    }
  ]
}

Share the love

Leave a Reply

Your email address will not be published. Required fields are marked *