Item requirement picking list posting from code

This question is not answered

Hi all,

I want to post the picking list for a sales line in the item requirement form from code, but I don't know how to do this. I've tried and failed so far. It looks like the salesformletter_pickinglist class is not capable of posting just 1 salesline.

The form is under: Project - Inquiries - Item Task - Item Requirement.
Then select a sales line, and click Posting - Picking List

How to do this from code?

Can anyone provide a sample?
I can't be the first to try this, right?

Thanks in advance,

Best regards
Klaas.

All Replies
  • Hi everyone,

    Just wanted to share to solution I worked out.

    void run()
    {
        #OCCRetryCount

        SalesLine       salesLineLoc;
        SalesTable      salesTableLoc;

        SalesFormLetter salesFormLetter;

        SalesParmLine   salesParmLine;
        SalesParmTable  salesParmTable;
        SalesParmUpdate salesParmUpdate;

        Qty             updateqty;
        ;

        while(this.queryRun().next())
        {
            try
            {
                ttsbegin;
                salesLineLoc = this.queryRun().get(tablenum(SalesLine));
                salesTableLoc = salesLineLoc.salesTable();

                // create formletter
                salesFormLetter = SalesFormLetter::construct(DocumentStatus::PickingList);
                salesFormLetter.createFromLines(true);
                salesFormLetter.createParmUpdate();

                // create parm table
                salesFormLetter.createParmTable(salesParmTable, salesTableLoc);
                salesParmTable.insert();

                // update salesparmupdate with values
                salesParmUpdate                 = salesFormLetter.salesParmUpdate();
                salesParmUpdate.Proforma        = !this.parmUpdate();
                salesParmUpdate.Reserve         = this.parmReserve();
                salesParmUpdate.SpecQty         = this.parmSalesUpdate();
                salesParmUpdate.ReduceOnHand    = this.parmSalesReduceOnHand();
                salesParmUpdate.selectForUpdate(true);
                salesParmUpdate.update();

                // don't print
                salesFormLetter.printFormLetter (false);

                // lookup quantity
                updateqty = SalesQuantity::construct(DocumentStatus::PickingList).calcSalesQty(salesLineLoc, this.parmSalesUpdate());

                // create parmline for the sales line
                salesParmLine.ParmId = salesParmTable.ParmId;
                salesParmLine.TableRefId = salesParmTable.TableRefId;
                salesParmLine.initValue();
                salesParmLine.initFromSalesLine(salesLineLoc);
                salesParmLine.DeliverNow = updateqty;
                salesParmLine.RemainBefore = updateqty;
                salesParmLine.RemainAfter = updateqty;
                salesParmLine.InventNow = updateqty;
                salesParmLine.RemainBeforeInvent = updateqty;
                salesParmLine.RemainAfterInvent = updateqty;
                salesParmLine.insert();

                // run
                salesFormLetter.run();
                ttscommit;
            }
            catch (Exception::Deadlock)
            {
                retry;
            }
            catch (Exception::UpdateConflict)
            {
                if (appl.ttsLevel() == 0)
                {
                    if (xSession::currentRetryCount() >= #RetryNum)
                    {
                        throw Exception::UpdateConflictNotRecovered;
                    }
                    else
                    {
                        retry;
                    }
                }
                else
                {
                    throw Exception::UpdateConflict;
                }
            }
            catch
            {
                exceptionTextFallThrough(); 
            }
        }
    }

    Best regards,
    Klaas Deforche.