web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Trigger Approval in Da...
Power Apps
Unanswered

Trigger Approval in Dataverse Web API

(0) ShareShare
ReportReport
Posted on by 36

Hi is there a way to trigger Approvals [Approve / Reject] via Dataverse Web API? 

 

image.png

I have the same question (0)
  • ivan_apps Profile Picture
    2,187 Moderator on at

    Do you mean to respond to an existing approval or to create an Approve/Reject approval and assign it to someone?

     

    There is an ‘Approvals’ table in Dataverse where the approval process is recorded behind the scenes of the Approvals flows. The approvals flow is simply a UI interface for records created in this table, if you create new table rows then the UI will show it. 

    You can use the Web API to create new rows, or if you have an exiting Approval row ID, you can send an update to record the Approve or Reject response. Take a look at the Dataverse Rest Builder tool to view how to create these queries, it will provide you the proper syntax for you. 

  • johnryanrobles Profile Picture
    36 on at

    Hi yes, I need to approve the existing approvals via dataverse WEB API , can you share to me the rest builder to trigger it? Thanks!

  • ivan_apps Profile Picture
    2,187 Moderator on at

    I'll show you how to use the Dataverse Rest Builder tool (DRB)

    1. Retrieve all Active Approval assigned to you

    ivan_25_1-1699885370134.png

    Xrm.WebApi.online.retrieveMultipleRecords("msdyn_flow_approval", "?$filter=_ownerid_value eq 12766fd2-a152-eb11-bb24-000d3a9c3679 and statecode eq 0").then(

    ivan_25_2-1699885451157.png

     

    2. Update the record you want (based on the Primary ID you want to update from #1)

    ivan_25_3-1699885762511.pngivan_25_4-1699885800346.png

    There are many methods of using the Web API to execute your actions, you can chose which method via the DRB tool.

     

    JS

    var record = {};
    record.statecode = 1; // State
    record.statuscode = 192350004; // Status
    
    var updateRequest = {
    	etn: "msdyn_flow_approval",
    	id: "60b8fff0-5dce-43e7-9073-eeb6e7421ffa",
    	payload: record,
    	getMetadata: function () { return { boundParameter: null, parameterTypes: {}, operationType: 2, operationName: "Update" }; }
    };
    
    Xrm.WebApi.online.execute(updateRequest).then(
    	function success(response) {
    		if (response.ok) {
    			console.log("Record updated");
    		}
    	}
    ).catch(function (error) {
    	console.log(error.message);
    });
  • johnryanrobles Profile Picture
    36 on at
    Hi Ivan, what should we update is it the request created from Approval Request Table right that is assigned to user?
  • ivan_apps Profile Picture
    2,187 Moderator on at

    Yes I imagine that you are retrieving active approval requests assigned to a specific user (maybe current logged in user). Modify the retrieval query to put in the appropriate owner GUID. You do the retrieval first to get all those records + any additional filter criteria you may have based on your use case.

     

    You can then iterate through the results and update the status of the approval request. The approval flow UI should display the update once you execute the update function. 

     

    I hope that answers your questions and gets you on the right path.

  • johnryanrobles Profile Picture
    36 on at

    Hi Ivan, i was able to retrieve the owner id and the approval request id from the Approval request table.

    {"@odata.etag":"W/\"44976130\"","msdyn_flow_approvalrequestidx_owninguserid":"74503F71-FE6B-E911-A81B-000D3A37F60D","statuscode":1,"msdyn_flow_approvalrequestid":"469e0630-bdff-419c-87b1-477d488f82b9","msdyn_flow_approvalrequestidx_approvalid":"7FA8A954-34F1-4B6E-8834-A5E0D30B9E10","statecode":0,"_ownerid_value":"74503f71-fe6b-e911-a81b-000d3a37f60d","createdon":"2023-11-16T05:04:26Z","msdyn_flow_approvalrequest_approval":{"_ownerid_value":"74503f71-fe6b-e911-a81b-000d3a37f60d","msdyn_flow_approval_title":"Second Testing","msdyn_flow_approval_source":"Approvals","msdyn_flow_approval_details":null,"createdon":"2023-11-16T05:04:25Z","msdyn_flow_approval_priority":192350002,"statecode":0,"statuscode":192350001,"msdyn_flow_approvalid":"7fa8a954-34f1-4b6e-8834-a5e0d30b9e10"}},

       What field should we update to process the approval request? How can i do that via dataverse web api/ dataverse client. 

     

    Thanks!

  • Daved1 Profile Picture
    166 on at

    There is a pretty good video on Approvals and Dataverse - Demystifying Modern Approvals Data Storage in Dataverse | Data model | CDS | Power Platform - YouTube.  Several Tables involved with Approvals (Approval, Approval Request, Approval Response)

     

    I hope this helps

    Dave

  • ivan_apps Profile Picture
    2,187 Moderator on at

    Take a look at my previous post here and the JavaScript section.

    var record = {};
    record.statecode = 1; // State
    record.statuscode = 192350004; // Status

     

    You have to send a POST request with an object of the fields to update. In this case, update the State and Status Code.  If you respond to approve- State=1 makes it Inactive, and Statuscode = 192350004 is the Approved status option that is allowed only when the record is Inactive. 

  • johnryanrobles Profile Picture
    36 on at

    Hi Ivan will this create a record also on approval response? since the records are created on approval request for specific approvers then the response go to approval response.

  • ivan_apps Profile Picture
    2,187 Moderator on at

    I don't believe it will. If you want to record a specific response and not the 'final' response to the approval flow, then update the Approval Response table.  That may cascade the response up if you set up the approval flow to be 'first to respond'.  Otherwise i assume it will wait for everyone to respond.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard