Use OneDrive Excel file as an external source for your Public Web Form fields
Populate fields on your form with data from an Excel file
Previously, I’ve already demonstrated how to retrieve data from SharePoint list and Dynamics 365 Business Central. Now, I will show you how to get data from Dynamics 365 CRM and utilize it in a web form designed with Plumsail Forms. Since at the time of writing this article, Microsoft Graph API does not provide methods for retrieving data from Dynamics CRM, we will use its native API and perform operations on behalf of a specific user. You can also configure app only access and you will find a link to the corresponding documentation describing extra steps you need to follow below but here I’ve tried to demonstrate the most straightforward way of getting data without additional configuration of the Dynamics CRM.
This my form with the drop-down field populated from Dynamics CRM:
First, we need to register a new Azure AD app with access to Dynamics CRM API.
Now, we need to configure permissions for the app:
Finally, we need to create a client secret for our app to use it in Azure Function:
You can deploy sample functions for retrieving Contacts and Accounts directly from our GitHub repository. After the deployment, we’ll need specify client ID and client secret of our Azure AD app, Microsoft 365 tenant, and URL of Dynamics CRM in the Function App settings.
Once the project is built and deployed, you will find the functions in your Function App. Now, we need to configure it by specifying the Azure AD app properties and URL of the Dynamics CRM.
Dynamics365.CRM:AzureApp:ClientId
The Application (client) ID of the Azure AD app
Dynamics365.CRM:AzureApp:ClientSecret
The Client secret of the Azure AD app
Dynamics365.CRM:AzureApp:Tenant
Your Microsoft 365 tenant, ex.: contoso.onmicrosoft.com
Dynamics365.CRM:AzureApp:DynamicsUrl
URL of the Dynamics CRM, ex.: https://contoso.crm.dynamics.com
Since we configured the Azure AD app with delegated permissions, we need to grant permissions to our app for requesting data from Dynamics CRM on behalf of specific user. In the Function App, you can find the D365-CRM-Authorize function that is designed specifically for providing delegated permissions. You need to call this function, sign in as a user with access to data you want to retrieve, and accept the permissions. Once you approve the request, D365-CRM-Authorize saves access token in cache for using in other functions. Thus, the end-users won’t be asked for permissions. All requests will perform on behalf of a user who provided consent to the app in the D365-CRM-Authorize function.
Alternatively, you can configure app only permissions for your Azure AD app. In this case, you won’t need to provide user consent to the app and perform operations on behalf of that user. Instead, you will be able to specify granular permissions to your app in Dynamics CRM and use just client ID and client secret for app’s authentication. For this, you need to create Application User for Azure AD app in your Dynamics CRM and configure its roles.
Before calling the D365-CRM-Authorize function, we need to add its URL to Redirect URI’s of the Azure AD app:
Finally, we need to enable Cross-Origin Resource Sharing (CORS) for our app to allow JavaScript requests from our web form:
Now, we’re ready to design a web form that utilizes data from Azure functions. For this article, I created a simple web form for sending messages to persons from the Contacts list of Dynamics 365 CRM.
First, copy the name of the field for using it in JavaScript:
Next, switch to JavaScript editor and add the code below. Do not forget to insert the correct field name and URL of your Azure function:
fd.rendered(function() {
var widget = fd.field('Contacts').widget;
widget.setDataSource({
transport: {
read: '-- URL of D365-CRM-Contacts function --'
}
});
widget.setOptions({dataTextField: 'fullname', dataValueField: 'emailaddress1'});
});
Please note that I specified different fields for dataTextField and dataValueField. Thus, a user will select contacts by their names while the submission will contain their emails. So, during processing the submission in Microsoft Power Automate or Zapier, we can send the message directly to the selected contacts without extra requests to Dynamics CRM.
This is my final form:
In previous articles, I’ve described how to retrieve data from Dynamics 365 Business Central and SharePoint list. All samples are gathered in a single GitHub repository, please use it as a starting point for your integrations. Feel free to leave your questions in the comments. If you need to connect your public web form to another data source, just let me know in the comments and possibly I will demonstrate it in one of the future posts.