For orders in AX (I am addressing sales orders specifically here), if you want to unpick an order, you have to go to the sales line and, one-by-one, unpick the order. You click on the Inventory button and select the Pick option. In the form, check the autocreate box, then click Post All in the lower area of the form. If you regularly have to pick and unpick orders, especially if you have a lot of lines on your orders, this can become very tedious.
I wrote a job that will unpick the entire order. Now I'm going to put an Unpick button on the sales order form at the order level and allow certain users (security will be used) to do this. I will most likely allow multiple orders to be selected so you can unpick multiple orders with one click of a button. The code for the job I wrote is below:
// For testing, I set the salesid here.
// In the final code, I will have to pass in the salesTable record
// from the salesTable_ds of the form
SalesId salesid = 'RSO948671';
TmpInventTransWMS tmpinventTransWMS;
InventMovement movement;
InventTrans inventTrans;
salesline salesline;
inventtransWMS_pick inventTransPick;
;
while select salesline
where salesline.SalesId == salesId
{
select inventTrans
where inventTrans.TransRefId == salesline.SalesId &&
inventTrans.ItemId == salesline.ItemId &&
inventTrans.StatusIssue == StatusIssue::Picked;
if(inventTrans.RecId)
{
movement = null;
movement = InventMovement::construct(salesLine);
inventTranspick = new InventTransWMS_Pick(movement,tmpInventTransWMS);
tmpInventTransWMS = null;
tmpInventTransWMS.initFromInventTrans(inventTrans);
tmpInventTransWMS.InventQty = inventTrans.StatusIssue == StatusIssue::Picked ? inventTrans.Qty : -inventTrans.Qty;
tmpInventTransWMS.insert();
inventTransWMS_pick::updateInvent(inventTransPick, tmpInventTransWMS);
}
}
Hello, thank you for the tip.
ReplyDeleteI copy-paste the lines, but don't work. In my job, there are error in the line "inventTranspick = new InventTransWMS_Pick(movement,tmpInventTransWMS);", because the method "new" don't have this parameters, only there "...new
InventTransWMS_Pick();", do you know why?
And, the last line "inventTransWMS_pick::updateInvent(inventTransPick, tmpInventTransWMS);" dynamics tell me the first parameter is not compatible because the parameter should be "Common _movementRecord).
(sorry my english, I going to study, lol)
yercar - thanks for reading my blog.
DeleteInventTransWMS_Pick extends the class InventTransWMS, the 'new' method is on the InventTransWMS class and looks like this:
void new(
InventMovement _movement,
TmpInventTransWMS _tmpInventTransWMS)
{
movement = _movement;
tmpInventTransWMS = _tmpInventTransWMS;
}
Perhaps you (your company) have overridden the new() method on the InventTransWMS_Pick class and replaced it with something else so that the InventTransWMS new() method is no longer called.
The first parameter of the InventTransWMSPick::updateInvent method is InventTransWMS_Pick. Again, have you customized this method? Here is the call for the method:
server static void updateInvent(InventTransWMS_Pick _inventTransPick, TmpInventTransWMS tmpInventTransWMS)
{
// lots of code in between
}
Good luck!
hi do you have code to pick item for sales order line based on batch no
DeleteYour while select statement would just include a join to the inventDim table (join inventdim where inventdim.inventdimid == salesLine.inventdimId && inventDim.inventBatchid == 'YourBatchNumber').
DeleteYour select statement for inventTrans would need to find statusIssue < StatusIssue::Picked (or look in the inventTrans table and see what your exact StatusIssue should be for your unpicked records - might be reserved, etc.).
Then you would only need to set your inventQty to negative inventTrans.Qty like this (rather than the code above that keys off of the picked status):
tmpInventTransWMS.InventQty = -inventTrans.Qty;