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

Announcements

No record found.

News and Announcements icon
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,097 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,429 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,097 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,429 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 804

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 639 Super User 2026 Season 1

#3
Subra Profile Picture

Subra 528

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans