Tutorial 5 - Add a custom action button to insight card to invoke REST
A capability to add custom-defined actions to insight cards is introduced and is currently available in preview.
New button types are introduced to Create card for assistant V2 operation.
Examples use case
We will create an insight card that will be displayed when an opportunity estimated closing date is within a day and we will add an action to extend estimated closing date by 10 days.
Test Data
Create one or more opportunities where the estimated closing date is current date.
Step 1: Create a trigger to start the flow
Set a trigger that runs every morning at 8 am.
In the search, enter Recurrence. From the search results, under the Triggers option, select Recurrence.
You'll see the below trigger. Enter Interval as 1 and select Frequency as Day. This ensures that the trigger will run once in day.
The other columns can be set according to your requirement. In this example, we are setting At these hours as 8, as we want the trigger to run every morning at 8 AM.
Step 2: Get all opportunities which are closing today
Select New Step and in the search box, enter Microsoft Dataverse and choose List Records.
Add a filter query to retrieve all opportunities closing today.
estimatedclosedate eq @{formatDateTime(utcNow(), 'yyyy-MM-dd')}
Step 3: For every opportunity create custom insight card
For all opportunities fetched from previous step, we will use new operation Create card for assistant V2 and create an insight card.
Click New Step below List records action and add Apply to each action.
Select all opportunities from Dynamic content for iteration.
In Apply to each operation, select Add an action and search for Sales Insight. You will see sales insight action as shown in introduction section, choose Create card for assistant V2 operation.
Enter environment and other details as required. To learn more, see Tutorial 1: Hello world.
You can observe that Extend Close Date is used as the button text.
We will make Extend Close Date to extend the estimated close date of related opportunity using REST.
Action using REST
Select button type as REST and add OData endpoint with the opportunity ID selected from previous step. In body of REST, add a dynamic json with future date, 10 days from today, and select method as PATCH.
{"estimatedclosedate": "@{getFutureTime(10, 'Day', 'yyyy-MM-dd')}"}
Step 4: Save the flow
Step 5: Test the flow
When the flow runs as scheduled or you run it manually, you should have a card created and displayed on dashboard as shown below.
We have our defined action available as the button on sales insights card.
Click on Extend Close Date. The opportunity will be updated with the new estimated close date and a confirmation message is displayed.
We extended the opportunity's estimated closing date with new action using REST call.