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, ...
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
    on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 507 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 419 Super User 2026 Season 2

#3
CU-1234529-002 Profile Picture

CU-1234529-002 155

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans