Exercise - Create instant plug-ins

Completed

In this exercise, you'll build an instant plug-in to calculate the debt ratio. This plug-in is reusable from Power Apps or Power Automate and isn't tied to any Dataverse table row. You'll also build an instant plug-in that does the same calculation but uses the data from a Dataverse row.

Important

Use a test environment with Microsoft Dataverse provisioned and with sample apps. If you don't have one, you can sign up for the Power Apps Developer Plan.

Task - Prepare your environment

To prepare your environment, follow these steps:

  1. Go to Power Apps maker portal.

  2. Select the correct environment and then select Solutions.

  3. Select New solution.

    Screenshot showing the create new solution button.

  4. Enter Learn Low Code Plugins for the Display name, enter LearnLowCodePlugins for the Name, and then select the + New publisher button.

  5. Enter Contoso for the Display name, enter Contoso for the Name, enter contoso for the Prefix, and then select Save.

  6. Select the Contoso publisher that you created and then select Create.

    Screenshot showing the create new solution dialog.

Build a plug-in to calculate debt ratio

  1. Go to Power Apps maker portal.

  2. Select the correct environment and then select Apps.

  3. Select the All tab, select Dataverse Accelerator App, and then select the Play button.

    Screenshot showing the play app button.

  4. Select Create instant plug-in.

  5. Enter Calculate Debt Ratio for the Display name and then select + New input parameter.

  6. Enter Income for the Label, select Decimal for the Data type, and then select + New input parameter.

  7. Enter HousingDebt for the Label, select Decimal for the Data type, and then select + New input parameter.

  8. Enter OtherDebt for the Label and select Decimal for the Data type.

  9. You should now have three input parameters. Select + out parameter.

  10. Enter TotalDebtRatio for the Label, select Decimal for the Data type, and then select + New out parameter.

  11. Enter HousingDebtRatio for the Label and then select Decimal for the Data type.

    Your input and output parameters should resemble the following image.

    Screenshot showing the input and output parameters.

  12. The following formula calculates housing debt ratio and total debt ratio. Paste the following Power Fx formula in the Expression field and then expand the Advanced options section.

     {TotalDebtRatio: ((HousingDebt + OtherDebt)/Income) * 100, HousingDebtRatio: (HousingDebt/Income) * 100};
    
  13. Select the LearnLowCodePlugins solution that you created for Solution and then select Global.

    Screenshot showing the selected solution and scope.

  14. Select Save and wait for the plug-in to be saved.

  15. Select the Test button. The test button appears after the plug-in is saved successfully.

  16. Enter 12000 for Income, 4000 for HousingDebt, 4000 for OtherDebt, and then select Run.

    Screenshot showing the run button.

  17. You should get a success response with the calculated TotalDebtRatio and HousingDebtRatio.

    Screenshot showing the response.

  18. You can close the Dataverse Accelerator App browser window or tab.

Task - Build plug-in to calculate contact debt ratio

  1. Navigate to Power Apps maker portal.

  2. Select the correct environment and then select Solutions.

  3. Open the Learn Low Code Plugins solution you created.

  4. Select Add exiting and then select Table

  5. Select the Contact table and then select Next.

    Screenshot showing the add existing table dialog.

  6. Choose the Select objects link button.

  7. Select the Forms tab.

  8. Select the Contact Main form and then select Add.

  9. Select Add again.

  10. Open the Contact table you just added to the solution.

    Screenshot showing the contact table.

  11. Select New and then select Column.

  12. Enter Housing Debt for Display name, select Currency for Data type, and then select Save.

  13. Select + New and then select Column again.

  14. Enter Other Debt for Display name, select Currency for Data type, and then select Save.

  15. The columns you added should look like the following image. Select Forms.

    Screenshot showing the added columns.

  16. Open the Contact form you added to the solution.

  17. Select the Details tab.

  18. Add the Annual income, Housing debt, and Other debt columns below the Credit limit column.

  19. Select Save and publish and wait for the publishing to complete.

  20. Select the <- Back button.

  21. Select the Contact table.

  22. Select the Edit button

    Screenshot showing the edit button.

  23. Select the chevron button next to the New row button and then select New row using form.

    Screenshot showing the new row using form button.

  24. Enter John for First name, Doe for Last name, and then select the Details tab.

  25. Enter 120000 for Annual income, 40000 for Housing debt, 40000 for Other debt, and then select Save.

    Screenshot showing the new contact.

  26. Copy the contact ID from the URL and keep it in a notepad, you use this ID to test the plugin. The ID is the GUID at the end of the URL ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.

  27. Select Save and Close.

  28. Select Done.

  29. Select the Back button.

  30. Select the Back to solutions button.

  31. Select Apps, select the All tab, and launch the Dataverse Accelerator App.

  32. Select Create instant plug-in.

    Screenshot showing the create instant plug-in card.

  33. Enter Calculate Contact Debt Ratio for Display name and then select New out parameter.

  34. Enter HousingDebtRatio for Label and select Decimal for Data type.

  35. Select New out parameter again.

  36. Enter TotalDebtRatio for Label and select Decimal for Data type.

  37. Expand the Advanced options section.

  38. In order to have "this record" available in the expression, first we need to set scope. Select LearnLowCodePlugins for solution, select Entity for Scope, and select Contact for Table.

    Screenshot showing the plug-in solution and scope.

  39. Paste the following expression in the Expression field. This expression shows an error if the total debt-to-income ratio is higher than 40%.

     {TotalDebtRatio: ((ThisRecord.'Housing Debt' + ThisRecord.'Other Debt')/ThisRecord.'Annual Income') * 100, HousingDebtRatio: (ThisRecord.'Other Debt'/ThisRecord.'Annual Income') * 100}
    
  40. Select Save and wait for the plugin to be saved.

  41. Select the Test button.

  42. Paste the contact ID you copied earlier and then select Run.

    Screenshot showing the run plug-in test button.

  43. You should get a success response and the calculated total debt and housing debt values.

    Screenshot showing the test response.