Batch jobs in D365: a Russian roulette

Batch jobs in D365: a Russian roulette

Real world production scenarios include automated batch tasks executed in the background with some cadence: Batch processing overview – Finance & Operations. They apply to sets of documents fetched at the run time, for example to sales orders delivered, but not invoiced yet. Obviously, every day the query with the documents should return a different set with the recently despatched sales orders. It is called Late selection: Late selection in D365FO – D365Tour. So far so known.

As the complexity of the business grows, so does the complexity of the batch jobs. You’ll need jobs consisting of multiple tasks, executed one after another. It is called task dependency, or task Constraints. One of the latest unpleasant discoveries was the fact, that you cannot always rely on the sequence of steps set in the batch job: the most useful tasks, such as the SalesFormLetter_Invoice and its likes (used to update sales and purchase orders with order confirmations, delivery notes and invoices) act as orchestrators and spin off child batch tasks for simultaneous, multi-threaded sales order, purchase order, production order processing. These child tasks are not constrained (!) and get executed at a first come, first served basis. They may still run while the master task SalesFormLetter_Invoice seemingly ends and relays the baton to the next task. This leads to interference and racing conditions. You better evaluate the average execution time of the master controller task as a whole, put these controllers into different batch jobs, schedule them at a safe time distance from one another.

Heterogenous batch jobs as the one shown below pose a different challenge.

Here is the how-to instruction:

  1. Spin off the first task from the main menu (here: Production control > Periodic tasks > Production order status update) and choose Run in the background / Batch processing. This will be your starting point, a template for the batch job.
  2. Locate the batch job in the My batch jobs list, set the status to Withheld and start editing.
  3. Every task within a batch job needs a Class name. Now you know the class name of the first task: ProdMultiCostEstimation. To add the next task, you have to manually specify its Class name. The owners of this framework provided a lookup list, but it is slow and completely dysfunctional: it shows just a fraction of the possible executable RunBase or SysOperation classes, sometimes it crashes if there are some bad customizations in the source code. If you don’t know the class name, repeat the step 1 to reveal it.
  4. Add the next task, type the class name in. The first time it will take the system up to 20-30 seconds to accept and retrieve the Class description.
  5. Most batch tasks need a query. Click Parameters to populate it. Here you experience another nasty trait of the batch framework: the query shown is the last one you used in the system elsewhere. It is not necessarily the one really persisting at the batch task. Another user is not going to see your query criteria at all: only the owner/creator has the control. *1) *2) *3)
  6. On the Batch task details tab, Constraints, choose the predecessor task to build a chain. You many need to change the Expected status to Ended or error if the batch job has to continue with the next task on an error somewhere in the chain.
  7. Check the recurrence, remove the Alerts if needed, and put the Batch job back to Waiting.

1) Lessons learned: take a screenshot of every query and parameter, document it thoroughly to pass the maintenance to the Dynamics system administrator.

2) In certain cases a manually added task does not let edit the execution parameters and/or the query. Sometimes(e.g. on sales order updates) it helps to execute the same periodic task in the normal user session once. This is the reason why it is often hard to pre-configure the batch jobs in a “Golden Config” environment: it may need real transactions to execute against. Sometimes it wishes to be initialised from the main menu and nowhere else because badly programmed. In such a case, start your step 1 – the key task – from this critical periodic task. Should there be 2 such bitchy tasks in one batch job chain, it is over. They must be separated into different batch jobs.  

3) As a really bad surprize came the fact that even the owner has no control over the query: if you use the Late selection, in a chain of nearly identical tasks as the ones below, the QUERY OF THE LAST TASK IS APPLIED TO EVERY TASK of the kind, at least in the case of the production order status updates.

You should let the bloody job run one first time, then put the batch job back on hold and adjust the queries in the tasks once more, then save and re-activate the batch job.

WHS Label copies, Custom work, display methods on labels

WHS Label copies, Custom work, display methods on labels

Todays exercise is seemingly simple: print a voluntary number of warehouse label copies where the standard Dynamics 365 SCM only prints one. The ingredients are quite exquisite and variegated:


Let’s start with a proof of concept: print as many labels as there are items. Assuming there are 3 items on the license plate (pallet), let’s print the same label 3 times. This sounds simple, yet you need the latest and the coolest feature Enhanced license plate label layouts. With that feature you can finally carve a substring from Dynamics data, but also format numbers and dates. This is exactly what we need.

In Warehouse management > Setup > Document routing > Document routing layouts, every Zebra label template ends with something like
which is the instruction to the label printer how many copies to print. Now replace this line with
The quantity as a real number is truncated to an integer on the label, and the ZPL printer makes as many copies as there were pieces on the pallet.

Display method

A real game changer is now the ability to parse a display method on the WMSLicensePlateLabel table. Let Dynamics calculate the number of copies on the fly, leveraging the PackingQty factor which is the number of pieces in the topmost unit of the Unit sequence group. Assuming the unit sequence group is PCS-BOX i.e. pieces in boxes and if the nominal quantity per box is 20, for a license plate with 100 items on it I would like to have 5 copies of the label.

Extend the WMSLicensePlateLabel as follows
final class WHSLicensePlateLabel_Extension
display Num noOfCopiesSimple()
return int2Str(this.PackingQty > 1 ? any2Int(roundUp(this.Qty / this.PackingQty,1)) : 1);

and embed it into the ZPL code like this:

Now the number of copies is dynamic, configurable and obeys the master data settings.

Custom work

The high-end solution is to let the user override and decide how many copies to print. In order to do that, before the Print line in the Work template we need an extra screen of the Custom work type:
Custom work type

This brings the following prompt on the mobile device

You may also want to explore possibilities of simple validations and post-processing of the data captured on the Custom work screen:
Custom method tutorial.

The number of copies entered by the user is then interpreted by a more sophisticated display method:
display Num noOfCopies()
int noOfCopies;
WHSWorkLineCustom workLineCustom;
WHSWorkLine workLine;
select firstonly Data from workLineCustom
exists join workLine
where workLine.WorkId == this.WorkId
&& workLine.WorkType == WHSWorkType::Custom
&& workLineCustom.WorkId == workLine.WorkId
&& workLineCustom.LineNum == workLine.LineNum;
if (workLineCustom.Data)
noOfCopies = str2Int(workLineCustom.Data);
if (! noOfCopies)
noOfCopies = this.PackingQty > 1 ? any2Int(roundUp(this.Qty / this.PackingQty,1)) : 1;
return int2Str(noOfCopies);


Towards the deconsolidation in Dynamics Warehouse Management

Towards the deconsolidation in Dynamics Warehouse Management

The deconsolidation (opening of a complex packaging, quality control, taking small packages out of the larger packages announced by the supplier of the goods via ASN) seems to be a well-established process in SAP EWM, yet the implementation in Dynamics for SCM, its WHS module may turn cumbersome. Below is the workflow one may configure in Dynamics WHS out of the box:

Deconsolidation workflow

It all begins with an Advance Shipping Notice transmission and import. The invaluable – and only available – source on this topic is located here: Processing of inbound ASNs in Warehouse Management in AX ‘7’ ( The ASN creates an inbound load and a packing structure for a Purchase Order in Dynamics. I identified 2 distinct scenarios:

  • Multi-SKU: The packing structure contains multiple items in one single box (or on one pallet). Here one needs to understand that the Import project in Dynamics Data management must still be “pre-conditioned” with an XML file containing nested cases (boxes) and all 6 entities in the composite entity “Inbound ASN” even though the real message will not be using either the WHSInboundLoadPackingStructureCaseEntity (representing the nested license plates i.e. packing structure cases) nor the WHSInboundLoadPackingStructureCaseLineV2Entity (the one with the items in the packing case). My file for the pre-conditioning is here: InboundASN_ASNEntityConditioning, while the real message can be stripped down to 4 entities
    the load Id
    … the purchase order(s) in that load
    …… the parent license plate(s)
    ……… the content of the license plate
  • Multi-case: the ASN contains a packing structure (max. 1 level of depth) where the boxes (packing cases) are on the Parent License plate (i.e. pallet or master box), and the multiple items are in their own cases (boxes). An example is here: InboundASN_NestedLPCase. Let’s state one thing straight: the process does not work in this scenario. Let’s explore, why.

Nested LP (multi case) scenario

Once the ASN has been imported, navigate to Warehouse management > Loads > Open loads, then open Ship and receive / Packing structure:

The cases (aka nested license plates) 00708581a and 00708581b are on the parent license plate 00708581 and contain the items. Use the Mobile menu item License plate receiving to process this ASN. It displays the list of the items and let the parent and the nested license plates emerge at the default receipt location (here: DOOR). The system registers the parent and the nested LPs all right, but the stock of the items is on the parent LP only!

This fundamental flaw in Dynamics is well documented here: License plate receiving via the Warehouse Management mobile app and therefore becomes a ‘feature’, not a ‘bug’ 😉 They further suggest using a Pack to nested license plates indirect menu item to distribute the stock over the nested LPs in accordance with the ASN, but here is how it is going to end:
Pack to nested license plates

This action culminates in an “insufficient on-hand” error, because the moment you receive the parent LP, it generates the put-away work and reserves the whole freshly received quantity for the same. The stock cannot be moved (because this is what the Pack to nested license plates really does: creates a series of movements between the parent and the nested licence plates).

The typical approach is to let the put-away work be omitted with a Work policy, or be automatically performed for the stock to stay at some logical staging location right after the receipt. The split nested LPs are then distributed into the main storage with a Movement by template menu item. However, a movement by template does not support either the Disposition codes or the Quality management (Quality management for warehouse processes – Supply Chain Management), because both the QC methods are only allowed for purchase orders and production orders, not the movements. This essentially rules out the standard WHS quality control.

The only viable solution is to elevate the cases to parent LPs in the ASN interface, i.e. to convert nested cases to multiple “parents” of their own. This effectively reduces the nested-LP scenario to a multi-parent, multi-SKU one:

Multi-SKU scenario

The list of the Cases in the Packing structure is empty now; instead, one or many parent license plates contain one or many items each:

Now, the secret of the proper work processing, deconsolidation and the proper location determination is the staged Work template for the purchase order receiving process:
Location DOOR → DECO → Final BIN or bulk location

The DOOR location is considered the staging area before the deconsolidation, while the DECO location (injected by the Directive code = Stage in the work template / location directive) is the staging area after the deconsolidation where the put-away work is sorted and clustered for further processing:
Purchase order work template
The process needs 3 mobile menu items: License plate receiving – Work (one Work class ID) – Work (another class ID).

The Print work type here substitutes the Print checkbox on the menu item, because the latter is printed earlier when the parent LP is at the DOOR while it is considered a Multi-SKU license plate: it is going to be printed only once and the item number and the location are going to be empty. Also note the Stop work break after the deconsolidation part (lines 1-4) to interrupt the flow at the DECO staging location and transfer the duties from one warehouse team to another.

The second piece of the puzzle is the Work header break by the Item number: it will create as many work headers as there are items, all for the same parent LP, with a unique final Put location each. This location is nicely printed on the label, along with the Item ID, i.e. we have successfully reduced a Multi-SKU case to a single-SKU one to locate a unique bin by item.

At the deconsolidation station, the same parent LP is scanned over and over again and it randomly directs to the next open purchase work = item to be taken out from the parent LP. A quality control is nicely tied in (however, the ASN quantity as a whole may be either accepted or rejected; a single damaged piece may only be split in a separate movement process at a QC location if fully rejected first):
Deconsolidation process

The last piece of the puzzle is the Generate license plate option at the menu item for the purchase work processing:

It replaces the ambiguous Parent LP number with a fresh unambiguous LP number (see the Confirm target license plate step above). The same is used by the “put-away people” to initiate the final movement into the destination bin / bulk location (lines 5-6 in the Work template):
PO put-away process


The last trick may be a batch job (Warehouse management > Periodic tasks > Change inventory status) updating the Inventory status from Inbound to Available in every bin, bulk, floor location every 2 minutes. The reason is a potentially early reservation of the goods in the receiving / staging locations while the quality inspection might not yet have taken place. The sales order location directives consider the regular bin/bulk/floor locations only, and the reservation in the receiving area results in an empty Pick location in the outbound work.

Use the configuration from by blog Dynamics 365 SCM: Do not reserve in Inbound to force the non-reserveable inventory Inbound status upon all purchase orders.