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

sales invoice commodity codes

(0) ShareShare
ReportReport
Posted on by 1,205

Hi all, 

Happy new year, we've had a request from the users to add commodity codes for the sales invoice.  This is fine, we already have a class which adds a bunch of information to the sales invoice (see below)

I cannot get either of the lines

salesInvoiceTmp.CommodityCode = EcoResCategory::find(inventTable.IntrastatCommodity).Code;
salesInvoiceTmp.CommodityCode = EcoResCategory::commodityCode(inventTable.IntrastatCommodity);

to save to salesinvoicetmp, as far as i'm concerned both lines above should work.  When checking the tables in SQL i should get at least one code returned but the invoice is returning nothing.  What am I missing?  

class SalesInvoiceHandler
{
    [PostHandlerFor(classStr(SalesInvoiceDP), methodstr(SalesInvoiceDP, processReport))]
    public static void TmpTablePostHandler(XppPrePostArgs arguments)
    {
        SalesInvoiceDP dpInstance = arguments.getThis() as SalesInvoiceDP;
        SalesInvoiceTmp salesInvoiceTmp = dpInstance.getSalesInvoiceTmp();

        ttsbegin;
        while select forUpdate salesInvoiceTmp 
        {
			CustFormletterParameters	custFormLetterParameters = CustFormletterParameters::find();
            CustInvoiceJour				custInvoiceJour = custInvoiceJour::findRecId(salesInvoiceTmp.JournalRecId);
            CustInvoiceTrans			custInvoiceTrans;
            CustInvoiceTrans			custInvoiceTrans2;
            EcoResCategory				ecoResCategory;
            EcoResProduct				ecoResProduct;
            EcoResProductTranslation	ecoResProductTranslation;
            InventDim					inventDim;
            InventItemBarcode			inventItemBarCode;
            SalesLine					salesLine;

            select inventDim where inventDim.ConfigId == salesInvoiceTmp.ConfigId
                && inventDim.InventColorId == salesInvoiceTmp.InventColorId
                && inventDim.InventSizeId == salesInvoiceTmp.InventSizeId
                && inventDim.InventStyleId == salesInvoiceTmp.InventStyleId
                && inventDim.InventSiteId == ""
                && inventDim.InventLocationId == ""
                && inventDim.WMSLocationId == ""
                && inventDim.InventStatusId == "";

            select * from inventItemBarCode where inventItemBarcode.inventDimId == inventDim.inventDimId
                && inventItemBarCode.ItemId == salesInvoiceTmp.ItemId
                && inventItemBarCode.BarcodeSetupId == "EAN-13";
            salesInvoiceTmp.ItemBarCodeEAN = inventItemBarcode.ItemBarCode;

            select * from inventItemBarCode where inventItemBarcode.inventDimId == inventDim.inventDimId
                && inventItemBarCode.ItemId == salesInvoiceTmp.ItemId
                && inventItemBarCode.BarcodeSetupId == "GTIN-12";
            salesInvoiceTmp.ItemBarCodeUPC = inventItemBarcode.ItemBarCode;

            select firstonly * from custInvoiceTrans where custInvoiceTrans.SalesId == custInvoiceJour.SalesId
				&& custInvoiceTrans.InvoiceId == custInvoiceJour.InvoiceId
				&& custInvoiceTrans.InvoiceDate == custInvoiceJour.InvoiceDate
				&& custInvoiceTrans.numberSequenceGroup == custInvoiceJour.numberSequenceGroup
            join salesLine where salesLine.InventTransId == custInvoiceTrans.InventTransId
					join custInvoiceTrans2 where custInvoiceTrans2.RecId == salesLine.RefReturnInvoiceTrans_W;
            salesInvoiceTmp.OrigInvoiceId = custInvoiceTrans2.InvoiceId;

            InventTable inventTable = InventTable::find(salesInvoiceTmp.ItemId);

			salesInvoiceTmp.CommodityCode = EcoResCategory::find(inventTable.IntrastatCommodity).Code;
			//salesInvoiceTmp.CommodityCode = EcoResCategory::commodityCode(inventTable.IntrastatCommodity);
			
            if (custFormLetterParameters.PrintProductName)
            {
                select firstonly * from ecoResProduct where ecoResProduct.DisplayProductNumber == salesInvoiceTmp.ItemId
                    join ecoResProductTranslation where ecoResProductTranslation.Product == ecoResProduct.RecId;
                salesInvoiceTmp.Name = ecoResProductTranslation.Name;
            }

            salesInvoiceTmp.SumVATEuro = CurrencyExchangeHelper::curAmount2CurAmount(salesInvoiceTmp.SumTax, salesInvoiceTmp.CustInvoiceJourCurrencyCode, "EUR" , custInvoiceJour.InvoiceDate);

            salesInvoiceTmp.update();
        }
        ttscommit;
    }

}

pastedimage1577967910535v1.png

After getting my debugging working again, it seems like for some reason the code in the update salesinvoicetmp is not executing, it's skipping going into the method... why would this be? Handler class is supposed to execute after DP class.

pastedimage1577978159540v1.png

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    304,684 Super User 2026 Season 1 on at

    Hi jhowe,

    Happy new year!

    Do you mean to say that the code until line 9 is actually working and from line10 not? Or is the complete method skipped?

    If it is only on the while select, it might indicate that the temporary table is empty.

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
André Arnaud de Calavon Profile Picture

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

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 551

#3
CP04-islander Profile Picture

CP04-islander 408

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans