Example: Modifying Header Field in code
This article is applicable for both Mobile WMS for Dynamics 365 Finance & Supply Chain, as well as the version for Dynamics AX 2012, though the example is shown as an extension, the change can be applied directly in AX 2012
In this aticle, we will explore an example on how to change the default value in the Delivery Date Field for the Receive Orders page in Mobile WMS
The content of each Header or filter pane on each Mobile WMS page is declared in our DocumentHandler classes, which is any class, that extends MobDocumentHandler. In a document handler class a filter or header can be declared as follows:
/// <summary>
/// The filter for the receive order page.
/// </summary>
/// <returns>An XML formatted string containing the filter fields.</returns>
[MobReferenceDataMethod]
public MobReferenceData ReceiveOrderFilters()
{
MobReferenceDataConfiguration refData = new MobReferenceDataConfiguration();
MobRegistrationCollectorList regCollectorList = new MobRegistrationCollectorList(5,MobConstants::Warehouse(),"@SYS6437","@SYS6437","@SYS6437");
MobRegistrationCollectorDate regCollectorDate = MobRegistrationCollector::collectorFromEDT(extendedtypestr(WMSDlvDate));
regCollectorList.parmDataTable(methodStr(MobGetReferenceData,WarehouseFilterList));
regCollectorList.parmDataKeyColumn(extendedtypestr(InventLocationId));
regCollectorList.parmDataDisplayColumn(extendedtypestr(Name));
refData.addCollector(regCollectorList);
regCollectorDate.parmName(MobConstants::DeliveryDate());
regCollectorDate.isHeader(true);
regCollectorDate.parmId(10);
regCollectorDate.parmLabel("@SYS16056");
refData.addCollector(regCollectorDate);
refData.parmUseDynaFilter(true);
return refData;
}
The above example is from the class MobDocReceiveOrder, which incidently is the class and method we will exten in this example.
Things to notice:
The method is augmented with the attribute MobReferenceDataMethod
This tells the Mobile WMS Core, that this method returns reference data, which is the category Header field traditionally has fallen under.
The method returns a MobReferenceDataConfiguration object
This object contains the Header Configuration for the page, thereby it has the fields for the header.
This is the object we need to modify to change the values and behaviour of the header fields.
Now to change the default value of the Date collector, the following extension class including method, can be made:
[ExtensionOf(classStr(MobDocReceiveOrder))]
final class MobDocReceiveOrderDate_extension
{
public MobReferenceData ReceiveOrderFilters()
{
MobReferenceDataConfiguration refData = next ReceiveOrderFilters();
SetEnumerator collectors = refData.getCollectors().getEnumerator();
MobRegistrationCollector collector;
MobRegistrationCollectorDate regCollectorDate;
date dateToSet = return DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) + 200;
//Get the Date Collector, iterate through all the collectors
while (collectors.moveNext())
{
collector = collectors.current();
if (classidGet(collector) == classNum(MobRegistrationCollectorDate) && collector.parmName() == MobConstants::DeliveryDate())
{
//Found the right collector
regCollectorDate = collector;
//Modify default date to somewhere in the future
regCollectorDate.parmDefaultValue(date2str(dateToSet,123,2,DateSeparator::Hyphen,2,DateSeparator::Hyphen,4));
}
}
return refData;
}
}
In the above code, we take the MobReferenceDataConfiguration from the method we extend, we iterate over the collectors in the object, and when we find the right collector, we modify it with the new default value for the date.
All attributes for the registration collectors are available as parm-methods in the Registration Collector Objects, and can thereby be manipulated as well.