As we all know, the Canvas app is one of the most dynamic and configurable component of the Power platform, we can design the app by dragging and dropping elements onto a canvas, just as you would design a slide in PowerPoint. We can write Excel-like expressions for specifying logic and working with data.
But these expressions will not work for complex logic and here we can introduce Power Automate.
Now, it is well-known that Power Automate is a low-code, no-code solution to automation with various triggers that it supports including Event driven, HTTP request, Timer/Scheduled, and Manual flows. Manual/Button flows help in designing powerful Canvas Apps that can handle complex logic executions.
In this blog we will learn how to build a canvas app that should close Opportunity records in Dynamics 365 when a button is clicked.
Let’s get start, Navigate to https://make.powerapps.com/ and create new Canvas app from blank.
Provide App name and select tablet or Phone as per your requirement.
Connect to CDS and select opportunity entity in Data Source
Now, navigate to Insert tab and choose Gallery => Vertical Gallery.
Set this gallery to form and select a data source as Opportunity.
Then rename gallery component and in Item property add below expression to bind the opportunity’s view. (You can set any opportunity view as per requirement. In my case, I chose the “my opportunity” view).
Filter(Opportunities,'Opportunities (Views)'.'My Opportunities')
Now, add one more screen as shown below,
Again set Data source and Add fields on your form.
I have also added two buttons, to close the opportunity as Won or Lost.
To Navigate from one form to another, set below expression on “NextArrow”.
Navigate('Opportunity Modify',ScreenTransition.Cover)
Now, to populate selected opportunity data in Opportunity modify form’s fields, set the Data Source’s Item property as “’My Opportunity’.Selected”.
Now click on the Won button and Navigate to Action tab then select Power Automate and create new Power Automate with the ‘PowerApps button’ template.
It will look like bellow, add new action to update the opportunity’s est. revenue, est. closed date etc.
To fetch values from the canvas app, we have to set dynamic content as ‘Ask in PowerApps’.
Then initialize one variable with name as Request URL to store organization url.
Now as we need to close the opportunity as Won, so we have to call “WinOpportunity” API request. To trigger API Request call, we need to add “Invoke an HTTP request” action.
Then we have to provide details same as below, to invoke winOpportunity API.
POST [Organization URI]/api/data/v9.0/WinOpportunity
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
{
"Status": 3,
"OpportunityClose": {
"subject": "Won Opportunity",
"opportunityid@odata.bind": "[Organization URI]/api/data/v9.0/opportunities(b3828ac8-917a-e511-80d2-00155d2a68d2)"
}
}
Replace [Organization URI] with Request URL.
It will look like as bellow.
Now go back to your canvas app and associate our newly created Flow to the button.
Using below expression we can pass parameters to flow,
Opportunitywon.Run('My Opportunity'.Selected.Opportunity,DataCardValue3)
All SET !!! Now run your Canvas app and you can close your opportunity as won by clicking the button.
Similarly, you can invoke multiple requests for opportunity, case and any other entity as per your requirements.