web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Partial Product receipt using x++ in D365fo

(0) ShareShare
ReportReport
Posted on by 2,426

Good morning,

I am trying to do Partial Product Receipt through x code.

There are many blogs i found but i want to know what is the right way of doing.

static void PO_partialpackingslip(Args  args)
{
   PurchFormLetter PurchFormLetter;
   PurchTable PurchTable;
   date _ReceivedDate = systemDateGet();
   PurchId _purchId = "000403";
   PurchLine purchLine;
   ;

   PurchTable = PurchTable::find(_purchId,true);
   ttsBegin;
   while select forUpdate * from purchLine
       where purchLine.PurchId == PurchTable.PurchId
   {
       purchLine.PurchReceivedNow = 5;
       purchLine.update();
   }
   ttsCommit;
   purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
   //Enum name is recorded, label is registered
   //change enum on purchUpdate to change what value(s) are posted
   PurchFormLetter.update(PurchTable,"test",systemDateGet(),     PurchUpdate::ReceiveNow,AccountOrder::None,NoYes::No,NoYes::No);
}

I am not sure why we have to update PurchReceivedNow in the code?

Or should i have to do this way 

https://dynamicsaxinsight.wordpress.com/2015/10/22/ax-2012-post-product-receipt-of-purchase-order-in-xpp/

Please show some sample example how can i do partial product receipt using x .

Regards,

Have a nice day.

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi AX 2012 r3,

    It can be done both ways.

    In your code you need to update ReceivedNow because you are using PurchUpdate::ReceiveNow and in this case quantity to be posted will be copied automatically to PurchParmLine based on value in ReceivedNow field from PurchLine.

    I prefer using the way how it's describe in the article as you don't need to manipulate with data on PurchLine level.

  • AX 2012 r3 Profile Picture
    2,426 on at

    Hi Sergei,

    Hope you are fine.

    Thanks for your quick reply.

    The second option will be better in doing partial packing slip.

    Here i need to provide partial quantity. ?

    purchParmLine.ReceiveNow = 2;

    Please provide suggestion on this.

    Regards,

    Have a nice day.

  • Verified answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi AX 2012 r3,

    I have used this code for partial product receipt before. I set the purchParmLine.ReceiveNow to the partial quantity.

    purchTable    = PurchTable::find(this.parmPurchId());
    
    ttsBegin;
    // Create PurchParamUpdate table
    purchFormLetterParmData = PurchFormletterParmData::newData(
                            DocumentStatus::PackingSlip,
                            VersioningUpdateType::Initial);
    
    purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
    purchFormLetterParmData.createData(false);
    purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
    
    // Set PurchParmTable table
    purchParmTable.clear();
    purchParmTable.TransDate                = SystemDateGet();
    purchParmTable.Ordering                 = DocumentStatus::PackingSlip;
    purchParmTable.ParmJobStatus            = ParmJobStatus::Waiting;
    purchParmTable.Num                      = this.parmPackingSlipId();
    purchParmTable.PurchId                  = purchTable.PurchId;
    purchParmTable.PurchName                = purchTable.PurchName;
    purchParmTable.DeliveryName             = purchTable.DeliveryName;
    purchParmTable.DeliveryPostalAddress    = purchTable.DeliveryPostalAddress;
    purchParmTable.OrderAccount             = purchTable.OrderAccount;
    purchParmTable.CurrencyCode             = purchTable.CurrencyCode;
    purchParmTable.InvoiceAccount           = purchTable.InvoiceAccount;
    purchParmTable.ParmId                   = purchParmUpdate.ParmId;
    purchParmTable.insert();
    
    // Set PurchParmLine table
    select purchLine
    where purchLine.PurchId     == purchTable.purchId &&
          purchLine.LineNumber  == this.parmLineNumber();
    
    purchParmLine.InitFromPurchLine(purchLine);
    
    purchParmLine.ReceiveNow    = this.parmQty();
    purchParmLine.ParmId        = purchParmTable.ParmId;
    purchParmLine.TableRefId    = purchParmTable.TableRefId;
    purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
    purchParmLine.setLineAmount();
    purchParmLine.insert();
    
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
    purchFormLetter.transDate(systemDateGet());
    purchFormLetter.proforma(false);
    purchFormLetter.specQty(PurchUpdate::All);
    purchFormLetter.purchTable(purchTable);
    
    // This is the ID we hard code as the product receipt ID, if we do the posting via UI
    // user would have the option to manually enter this value
    purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
    purchFormLetter.parmId(purchParmTable.ParmId);
    purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
    purchFormLetter.run();
    
    ttsCommit;

    Please check if this works for you.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi AX 2012 r3,

    Yes, you need to fill purchParmLine.ReceiveNow quantity with the quantity you want to receive.

  • AX 2012 r3 Profile Picture
    2,426 on at

    Hi Gunjan,

    Thanks for the code share and yes it is working perfect.

    I just want to know  this.parmPackingslipId() in this are you generating number sequence ?

    Please show some light on this

    Regards,

    Have a nice day.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Ax 2012 r3,

    We were receiving the packing slip id from an external application.

  • AX 2012 r3 Profile Picture
    2,426 on at

    Ok Gunjan

    Thanks for your reply.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans