To post a packing slip in AX there are two main ways, either post it manually by clicking on button and filling in forms or writing X++ code. In Con Studio, each action can be overwritten with a custom handler The custom handler inherits the standard (part of Con studio) handler, like so;
class GAB_PackingSlipHandlerPO extends AppDataDocumentHandler
{
PurchFormLetter PurchFormLetter;
PurchLine purchLine;
PurchTable purchTable;
boolean success;
}
In this case, we need to read an XML file and based on some values in the file, update the purchase order and then post a packing slip. In theory there are a few different way to do this, in the end I decided to simply update the Receive Now quantity and then post the packing slip with the quantity (PurchUpdate::ReceiveNow). This will post the packing slip and update the inventory accordingly
First we need to set the Receive now; this is done in the BlockRead method.
boolean blockRead(AppDataBlock blockDefinition, AppEntity theEntity, AppBlock theBlock)
{
boolean ret;
int currentLine;
str textToLog;
;
success = false;
if(theEntity.getRecord().TableId == tablenum(PurchLine))
{
purchLine = theEntity.getRecord();
try
{
purchLine.PurchReceivedNow = purchLine.PurchReceivedNow + str2int (theBlock.value("InventReceivedNow"));
purchLine.setInventReceivedNow();
purchLine.update();
success = true;
}
catch(Exception::Error)
{
for(currentLine = 1; currentLine <= infolog.line(); currentLine++)
{
textToLog += 'n' + infolog.text(currentLine);
}
this.writeErrorToLog(purchLine, textToLog);
success = false;
return false;
}
}
else
{
ret = super(blockDefinition, theEntity, theBlock);
}
if(theEntity.getRecord().TableId == tablenum(PurchTable))
{
purchTable = theEntity.getRecord();
}return ret;
}
This method will iterate over all occurrences of the transaction level, set on the file. In this case that is the PurchTable (can be any table level defined in the file or the whole XML document)
After the entire file have been read, we need to post the packing slip, based on the now updated quantities. This is done in the TransactionCommit method.
{
PurchInternalPackingSlipId num;
str textToLog;
int currentLine;
InventTable inventTable;
;
super(blockDefinition, theEntity, theBlock);
num = NumberSeq::newGetNum(PurchParameters::numRefPurchPackingSlipId(),true).num();
purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
purchLine = PurchLine::findRecId(theBlock.value("RecId"));
if(success == true)
{
try
{
ttsbegin;
purchFormLetter.update(purchTable, num, Today(),PurchUpdate::ReceiveNow);
ttscommit;
}
catch(Exception::Error)
{
success = false;
for(currentLine = 1; currentLine <= infolog.line(); currentLine++)
{
textToLog += 'n' + infolog.text(currentLine);
}
this.writeErrorToLog(purchLine, textToLog);
purchLine.PurchReceivedNow = 0;
purchLine.setInventReceivedNow();
}
}
}
This should give you a good idea on how to use the Con Studio. There are more details but this is the basic logic required to get it working.
Inga kommentarer:
Skicka en kommentar