Tutorial 5 - Add a custom action button to insight card to invoke REST

Completed

A capability to add custom-defined actions to insight cards is introduced and is currently available in preview.

Dynamics 365 Sales Insights on the Actions tab of the search showing custom-defined actions preview.

New button types are introduced to Create card for assistant V2 operation.

Choose a button type dropdown has Custom action (CRM process) selected.

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. 

  1. In the search, enter Recurrence. From the search results, under the Triggers option, select Recurrence.

    Search results for recurrence show Recurrence Schedule on the Triggers tab.

  2. 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. 

    In the Recurrence dialog, the At these hours property is set to 8.

Step 2: Get all opportunities which are closing today

  1. Select New Step and in the search box, enter Microsoft Dataverse and choose List Records.

    Dataverse search results show on the Actions tab, and List records is selected.

  2. Add a filter query to retrieve all opportunities closing today.

    estimatedclosedate eq @{formatDateTime(utcNow(), 'yyyy-MM-dd')}

    Filter query is set to estimatedclosedate eq formatDateDime(...).

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.

  1. Click New Step below List records action and add Apply to each action.

    Apply to each search results show the Apply to each Control on the Actions tab.

  2. Select all opportunities from Dynamic content for iteration.

    Select all opportunities from Dynamic content.

  3. 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.

    Select the Create card for assistant V2 operation.

  4. Enter environment and other details as required. To learn more, see Tutorial 1: Hello world.

    Enter environment, card name, card header, card text, and button text.

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

  1. 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')}"}

    Select button type as REST and add OData endpoint with the opportunity ID.

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.

Shows the Tutorial Card with Opportunity closing date is today. Verify estimated close date is correct or extend it.

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.