This is the third in a three-part series discussing Microsoft Dynamics 365 Finance and Operations (D365FO) in the context of the browser. In part one we explored creating bookmarklets and in part two we converted that bookmarklet into a browser extension. In part three we will make an extension that simplifies opening the D365FO table browser.
In part two we created a content script (content.js), which is necessary for a browser extension to be able to access content in the context of a currently open webpage. Browser extensions using the Chrome extension API can also include background scripts. Background scripts are necessary to access specific features of the API such as the Omnibox. The content scripts and background scripts execute in separate contexts, so communication between them typically falls to some sort of message passing protocol.
To create our D365FO table browser extension, we will:
- Expand messaging between background and content scripts
- Use the D365FO metadata API to gather a list of tables and form data sources that are related
- Use the Chrome options API to store the D365FO URL and related settings
- Use the Omnibox API to create a table browser keyword, and parse the first argument as the table name
Messaging
Messaging between the background script and content script in a browser extension gives the developer access to page content, while listening for notifications in a background script (or vice versa). The Chrome developer documentation provides the “hello world” example of message passing:
chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
console.log(response.farewell);
});
Building on that concept, we can listen for messages in our background script and when the content script detects the current page is a D365FO instance, we can infer the base D365FO instance URL for the table browser, which will follow a format like:
https://[base url]/?mi=SysTableBrowser&TableName=[table name]&cmp=[company name] &limitednav=true&lng=en-us
Metadata API
Using the metadata API we can generate a list of tables and formDataSources. With that information we can provide the user a list of tables to select from based on the current form. There are some great articles about the metadata API, including one by Martin Drab that shows the basics of how to get started with the new API. Another good article from Ievgen Miroshnikov shows how to get a provider, and then enumerate metadata elements.
For our purposes we will create an IMetaModelService by using the MetaModelServiceFactory and then iterate the list of tables and forms generating a .json file along the way. File handling in D365FO is pretty different from previous versions, so to simplify our task we will leverage the standard File::SendFileToUser(stream,fileName) method.
Chrome options
Chrome options give us the ability to store small pieces of data related to the extension, and to sync them across browsers. To do so, we will leverage the Chrome storage API.
Omnibox
The Chrome Omnibox allows for extension using a keyword, based on the Omnibox documentation.
We will use d3f2 as our keyword and [tablename] as the first argument so that the extension can be used for example as:
d3f2 salestable
By leveraging and combining these APIs we can produce our search result:
For improved usability we can include the developer documentation as well in our metadata information.
Bringing together the ideas from the previous blogs and building on the provided metadata from Microsoft, you can start to get an idea how Dynamics being browser based can bring opportunities for improved developer and user stories.
What ideas can you think of for a browser extension for Dynamics 365? Let us know, and thank you for reading.
This publication contains general information only and Sikich is not, by means of this publication, rendering accounting, business, financial, investment, legal, tax, or any other professional advice or services. This publication is not a substitute for such professional advice or services, nor should you use it as a basis for any decision, action or omission that may affect you or your business. Before making any decision, taking any action or omitting an action that may affect you or your business, you should consult a qualified professional advisor. In addition, this publication may contain certain content generated by an artificial intelligence (AI) language model. You acknowledge that Sikich shall not be responsible for any loss sustained by you or any person who relies on this publication.