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
In the previous article, I’ve demonstrated how to provide public access to specific SharePoint data via Azure Function and use it in a public form. Here, I want to show how to do the same with Dynamics 365 Business Central. In this example, I will use data from Customers, Vendors, and Items lists in a public web form designed with Plumsail Forms. But with minor adjustments of the Azure Function, you can retrieve other lists available via Microsoft Graph API including Accounts, Employees, Journal and others. You can also configure cascading drop-downs or filter data in any other way.
This is my form utilizing data from Dynamics 365 Business Central for populating the drop-down fields:
First, we need to register a new Azure AD app with access to financials data via Microsoft Graph 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 functions for retrieving data from Dynamics 365 Business Central directly from our GitHub repository. No need to modify source code to specify the app and data source properties, all of these can be configured via the Function App settings after the deployment:
Once the project is built and deployed, you will see the functions in your Function App. Now, we need to configure it by specifying the Azure AD app properties and the company name from Dynamics 365 Business Central you want to retrieve data from.
Dynamics365.BusinessCentral:AzureApp:ClientId
The Application (client) ID of the Azure AD app
Dynamics365.BusinessCentral:AzureApp:ClientSecret
The Client secret of the Azure AD app
Dynamics365.BusinessCentral:AzureApp:Tenant
Your Microsoft 365 tenant, ex.: contoso.onmicrosoft.com
Dynamics365.BusinessCentral:Customers:Company
The name of the company in Dynamics 365 Business Central which Customers are requested in D365-BC-Customers function
Dynamics365.BusinessCentral:Vendors:Company
The name of the company in Dynamics 365 Business Central which Vendors are requested in D365-BC-Vendors function
Dynamics365.BusinessCentral:Items:Company
The name of the company in Dynamics 365 Business Central which Items are requested in D365-BC-Items function
You might noticed the D365-BC-Authorize function among the others. Since Microsoft Graph API does not support app-only access to Dynamics 365, we had to create a separate function for providing permissions to Dynamics on behalf of a specific user. Before starting using other functions, you must call D365-BC-Authorize function and approve the requested permissions under a user with access to Dynamics 365 Business Central. You have to go through this step just once to allow end-users to call other functions anonymously without extra authentication. The Function App saves your credentials in cache for using in future requests:
Finally, we need to enable Cross-Origin Resource Sharing (CORS) for our app to allow JavaScript requests from our web form:
Finally, we can design a public web form and populate some fields from Azure Functions with JavaScript. In this example, I have Commercial proposal form with Customer, Vendors, and Items fields which I want to be populated from the corresponding functions.
First, I need to copy their names in the design mode:
Next, I switch to JavaScript editor and specify data source for those fields:
fd.rendered(function() {
var customerWidget = fd.field('Customer').widget;
customerWidget.setDataSource({
transport: {
read: '-- URL of D365-BC-Customers function --'
}
});
customerWidget.setOptions({dataTextField: 'displayName', dataValueField: 'displayName'});
var vendorsWidget = fd.field('Vendors').widget;
vendorsWidget.setDataSource({
transport: {
read: '-- URL of D365-BC-Vendors function --'
}
});
vendorsWidget.setOptions({dataTextField: 'displayName', dataValueField: 'displayName'});
var itemsWidget = fd.field('Items').widget;
itemsWidget.setDataSource({
transport: {
read: '-- URL of D365-BC-Items function --'
}
});
itemsWidget.setOptions({dataTextField: 'displayName', dataValueField: 'displayName'});
});
And that is it:
Previously, I’ve already demonstrated how to retrieve data from SharePoint Online. Now, you know how to do that with Dynamics 365 Business Central. If you have any specific requirements for your public web forms in part of working with external data or you want me to demonstrate integration with other services, just describe it in the comments. I’d be more than happy if my articles could help you making more functional and efficient forms. So do not hesitate to leave your questions.