Exercise - Create instant plug-ins
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.
Viktigt
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:
Go to Power Apps maker portal.
Select the correct environment and then select Solutions.
Select New solution.
Enter Learn Low Code Plugins for the Display name, enter LearnLowCodePlugins for the Name, and then select the + New publisher button.
Enter Contoso for the Display name, enter Contoso for the Name, enter contoso for the Prefix, and then select Save.
Select the Contoso publisher that you created and then select Create.
Build a plug-in to calculate debt ratio
Go to Power Apps maker portal.
Select the correct environment and then select Apps.
Select the All tab, select Dataverse Accelerator App, and then select the Play button.
Select Create instant plug-in.
Enter Calculate Debt Ratio for the Display name and then select + New input parameter.
Enter Income for the Label, select Decimal for the Data type, and then select + New input parameter.
Enter HousingDebt for the Label, select Decimal for the Data type, and then select + New input parameter.
Enter OtherDebt for the Label and select Decimal for the Data type.
You should now have three input parameters. Select + New output parameter.
Enter TotalDebtRatio for the Label, select Decimal for the Data type, and then select + New output parameter.
Enter HousingDebtRatio for the Label and then select Decimal for the Data type.
Your input and output parameters should resemble the following image.
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.
PowerApps Formula{TotalDebtRatio: ((HousingDebt + OtherDebt)/Income) * 100, HousingDebtRatio: (HousingDebt/Income) * 100};
Select the LearnLowCodePlugins solution that you created for Solution and then select Global.
Select Save and wait for the plug-in to be saved.
Select the Test in API playground button. The test button appears in the upper right of the screen after the plug-in is saved successfully.
Enter 12000 for Income, 4000 for HousingDebt, 4000 for OtherDebt, and then select Send.
You should get a success response with the calculated TotalDebtRatio and HousingDebtRatio.
Anteckning
If you encounter an error, it could be because your system is inserting a 1,000 comma separator in the background. Navigate back to edit the Calculate Debt Ratio in the Dataverse Accelerator App. Once there, change your Input Parameters from decimal to string type, and replace your expression with the following code. Then Update and try your test again.
PowerApps Formula{TotalDebtRatio: ((Value(HousingDebt) + Value(OtherDebt))/Value(Income)) * 100, HousingDebtRatio: (Value(HousingDebt)/Value(Income)) * 100};
You can close the Dataverse Accelerator App browser window or tab.
Task - Build plug-in to calculate contact debt ratio
Navigate to Power Apps maker portal.
Select the correct environment and then select Solutions.
Open the Learn Low Code Plugins solution you created.
Select Add existing and then select Table
Select the Contact table and then select Next.
Choose the Include all objects button, and then select Add to add the Contact table to your solution.
Back in your solution, open the Contact table you just added to the solution.
Select New and then select Column.
Enter Housing Debt for Display name, select Currency for Data type, and then select Save.
Select + New and then select Column again.
Enter Other Debt for Display name, select Currency for Data type, and then select Save.
Filter the Table to display Data type of Currency. The columns you added should look like the following image. Select Forms. (You may see other columns if you have added other currency columns to your Contact table.) Select Back to return to the Contact table settings.
Select Forms and then open the main contact form.
From the left hand Table columns pane, add the Annual income, Housing debt, and Other debt columns to the bottom of the form by clicking on each.
Select Save and publish and wait for the publishing to complete.
Select the <- Back button.
Select the Contact table to return to the contact table's main settings.
Select the Edit button in the Contact columns and data section.
Select the chevron button next to the New row button and then select New row using form.
Select the view called Contact to match the screenshot below. (It may be showing you a different view depending how you set up your form.)
Enter John for First name, Doe for Last name then enter 120000 for Annual income, 40000 for Housing debt, 40000 for Other debt. Select Save but do not close the screen.
Once you have saved, the URL will change to include the contact ID. Copy the contact ID from the URL and keep it in a notepad. You will use this ID to test the plugin. The ID is the GUID at the end of the URL, "ID=
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
".Select Save and Close.
Select Done.
Select the Back button.
Select the Back to solutions (left arrow) button from the left-side navigation rail.
Select Apps, select the All tab, and launch the Dataverse Accelerator App by selecting Play (the right arrow in the ellipses).
Select Create instant plug-in.
Enter Calculate Contact Debt Ratio for Display name, and then select New input parameter.
Enter ThisRecord for Label, select EntityReference for Data type, and find/select your Contact table for the table.
Select New output parameter.
Enter HousingDebtRatio for Label and select Decimal for Data type.
Select New out parameter again.
Enter TotalDebtRatio for Label and select Decimal for Data type.
Paste the following expression in the Expression field. This expression shows an error if the total debt-to-income ratio is higher than 40%.
PowerApps Formula{TotalDebtRatio: ((ThisRecord.'Housing Debt' + ThisRecord.'Other Debt')/ThisRecord.'Annual Income') * 100, HousingDebtRatio: (ThisRecord.'Other Debt'/ThisRecord.'Annual Income') * 100}
Expand the Advanced options section.
Select LearnLowCodePlugins for Solution.
Select the Scope of Entity, and then select the Contact table from the dropdown.
Select Save and wait for the plugin to be saved.
Select the Test in API playground button that appears in the upper right of the screen once your app successfully saves.
Paste the contact ID you copied earlier and then select Send.
You should get a success response and the calculated total debt and housing debt values.