Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Issue while marking via code.

(0) ShareShare
ReportReport
Posted on by

Hello team,

Shared below is my code, I have written 2 functions option1 and option 2 , unfortunately  both of them are unable to mark the transactions , please suggest a fix.

Class myClass
{
 Qty qty; // populated from other object in class
 InventtransId invetTransId; // populated from other object in class
 this.autoMarkTransaction( invetTransId, qty);
 
 public void autoMarkTransaction(InventtransId _inventTransId, Qty _qty =0)
 {
    RefRecId refOdrRecId;
    InventTransId refInventTransId;
    InventTransOrigin inventTransOrigin = InventTransOrigin::findByInventTransId(_inventTransId); 
	
        switch(inventTransOrigin.ReferenceCategory)
		
		 {
              case InventTransType::Purch:
                                refOdrRecId = PurchLine::findInventTransId(inventTransOrigin.InventTransId).RecId;
                                refInventTransId = PurchLine::findInventTransId(inventTransOrigin.InventTransId).InventTransId;
                                break;
								
              case InventTransType::TransferOrderReceive:
                                refOdrRecId = InventTransferLine::findTransIdReceive(inventTransOrigin.InventTransId).RecId;
                                refInventTransId = InventTransferLine::findTransIdReceive(inventTransOrigin.InventTransId).InventTransId;
                                break;
								
               case InventTransType::PmfProdCoBy:
                                RecId prodTableRecId = ProdTable::find(inventTransOrigin.ReferenceId).RecId;
                                refOdrRecId = PmfProdCoBy::find(inventTransOrigin.ReferenceId, prodTableRecId).RecId;
                                refInventTransId = PmfProdCoBy::find(inventTransOrigin.ReferenceId, prodTableRecId).InventTransId;
                                break;
               default:
                   break;              
         }
                       
             this.option1(inventTransOrigin.RecId, refOdrRecId, _qty);             //User either option1() or option2() //prefered option 1 as it calls underlying OOB code for marking
             //this.option2(inventTransOrigin.InventTransId, refInventTransId);    //Uncomment option 1 use option 2

}

 private  void option1(InventTransOriginId _inventTransId, InventTransOriginId _refInventTransId, InventQty _qty)
 {
    InventTransOrigin::updateMarking(_inventTransId, _refInventTransId, -1 * _qty);
 }			 
 private void option2(InventTransId issueInventTransId , InventTransId receiptInventTransId)//, InventQty _qtyTomark)
   {
       InventTransOriginId receiptInventTransOriginId = InventTransOrigin::findByInventTransId(receiptInventTransId).RecId;
       InventTrans receiptInventTrans = InventTrans::findByInventTransOrigin(receiptInventTransOriginId);

       InventTransOriginId issueInventTransOriginId = InventTransOrigin::findByInventTransId(issueInventTransId).RecId;
       InventTrans issueInventTrans = InventTrans::findByInventTransOrigin(issueInventTransOriginId);
       
        TmpInventTransMark tmpInventTransMark;
 
       InventTransMarkCollection collection = TmpInventTransMark::markingCollection(
        InventTransOrigin::find(receiptInventTransOriginId),
        receiptInventTrans.inventDim(),
        receiptInventTrans.Qty);

     
 
       collection.insertCollectionToTmpTable(tmpInventTransMark);
 
       select firstonly tmpInventTransMark
        where tmpInventTransMark.InventTransOrigin == issueInventTrans.InventTransOrigin
           && tmpInventTransMark.InventDimId       == issueInventTrans.InventDimId;
 
       if (tmpInventTransMark.RecId != 0)
       {
           Qty qtyToMark = issueInventTrans.Qty;
 
           tmpInventTransMark.QtyMarkNow =  qtyToMark;
           tmpInventTransMark.QtyRemain  -= tmpInventTransMark.QtyMarkNow;
 
           Map mapUpdated = new Map(Types::Int64, Types::Record);
           mapUpdated.insert(tmpInventTransMark.RecId, tmpInventTransMark);
 
           TmpInventTransMark::updateTmpMark(
                receiptInventTransOriginId,
                receiptInventTrans.inventDim(),
                -qtyToMark,
                mapUpdated.pack());
       }

   }


                    

Thanks in advance

Mav

  • Suggested answer
    Mav Profile Picture
    Mav on at
    RE: Issue while marking via code.

    Admin please delete, I resolved it myself by using correct inventtransid and reference id.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans