Microsoft Dynamics 365 Retail MPOS: Add custom filter in recall order search
Hello everyone, some time ago a customization request was raised from one of our Dynamics 365 Commerce clients to add a custom filter of ‘customer reference’ field from Dynamics 365 Finance and Supply Chain sales order in the recall order screen’s search options in MPOS.
The customization consists of two steps:
- Adding the custom filter to the MPOS screen
- Customizing the code in Dynamics 365 Finance and Supply Chain.
Adding the custom filter in recall order screen
In order to add the filter in recall order screen you have to create a view extension in the directory K:\RetailSDK\POS\Extensions\ if working in an azure hosted VM and for a local VM you have to do that in C:\RetailSDK\POS\Extensions\
Creating a view extension you have to perform a sequence of steps.
1. Start Microsoft Visual Studio 2017 or later as an administrator.
2. Open the ModernPOS solution from …\RetailSDK\POS.
3. In the POS.Extensions project, create a folder that is named RecallOrderSearch.
4. In the RecallOrderSearch folder, create a folder that is named ViewExtensions.
5. In the ViewExtensionsfolder, create a folder that is named SearchOrders.
6. In the SearchOrders folder, create a Typescript file that is named RecallOrderCustRefFilter.ts.
7. In the RecallOrderCustRefFilter.ts file, add the following code in the file.
8. You will now add the resource file for localization of the column name. In the SearchExtension folder, create a folder that is named Resources.
9. In the Resources folder, create a folder that is named Strings.
10. In the Strings folder, create a folder that is named en-us.
11. In the en-us folder, create a file that is named resources.resjson.
12. In the resources.resjson file, add the following code.
13. In the RecallOrderSearch folder, create a JSON file that is named manifest.json.
14. In the manifest.json file, add the following code.
15. In the POS.Extensions project, open the extensions.json file, and update it with RecallOrderSearch samples, so that the POS includes this extension at runtime.
After adding all the custom code clean and rebuild the project and start the project from visual studio it will show you custom changes in the recall order search bar.
Customizing the code in D365 Finance and Supply Chain
In order to customize the code in D365 Finance and Supply Chain we have to make changes in standard Microsoft service class RetailTransactionServiceTransactions. Microsoft provides delegates to handle different POS operations. registerGetListOrderSearchCustomfilterRanges delegate handle the custom filter which we added in the above steps.
For customizing the code you have to copy registerGetListOrderSearchCustomfilterRanges delegate and paste its signature in a new class RetailSearchOrderCustomFilterEvent to create an event handler. Then add the following code into it.
class RetailSearchOrderCustomFilterEvent
{
/// <param name=”customFiltersXmlElement”></param>
/// <param name=”extensionRanges”></param>
[SubscribesTo(classStr(RetailTransactionServiceTransactions), staticDelegateStr(RetailTransactionServiceTransactions, registerGetListOrderSearchCustomFilterRanges))]
public static void RetailTransactionServiceTransactions_registerGetListOrderSearchCustomFilterRanges(XmlElement customFiltersXmlElement, List extensionRanges)
{
container conRange;
XmlElement keyElement;
XmlElement searchFilterValue, valueNode;
XmlNodeList childNodes;
System.Collections.IEnumerator iEnumerator;
str fieldName;
str filterValueStr;
int loop = 0, counter = 0;
if (customFiltersXmlElement !=null)
{
keyElement = customFiltersXmlElement.firstChild();
if(keyElement !=null)
{
fieldName = “CustomerRef”;
childNodes = keyElement.childNodes();
counter = childNodes.length();
for(loop =0; loop < counter; loop++)
{
if(childNodes.item(loop).name() ==”SearchValues”)
{
valueNode = childNodes.item(loop).firstChild().firstChild();
break;
}
}
if(valueNode !=null)
{
childNodes = null;
childNodes = valueNode.childNodes();
counter = childNodes.length();
for(loop =0; loop < counter; loop++)
{
if(childNodes.item(loop).name() ==”StringValue”)
{
filterValueStr = childNodes.item(loop).innerText();
break;
}
}
}
}
}
if (filterValueStr)
{
conRange = conIns(conRange, conLen(conRange) + 1, fieldName);
conRange = conIns(conRange, conLen(conRange) + 1, filterValueStr);
extensionRanges.addEnd(conRange);
}
}
}
Validate the customization
Follow these steps to validate the customization.
- Sign in to Modern POS.
- Search for customer reference by using the custom filter in the search options. You should see the custom column that you added.
- Filtered orders should be displayed in the grid.