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, ...
Unanswered

Set sales tax on Purchase Order header and Lines using X++

(0) ShareShare
ReportReport
Posted on by 125

Hi Experts,

I'm trying to put sales tax on PO header in AX2009 using below code   

//for header
void createPOHeaderSalesTax(PurchTable _purchTable)
{
TmpTaxWorkTrans             tmpTax;
PurchTable                  purchTable;
PurchTotals                 purchTotalsSet;
TaxRegulation               taxRegulation;
TmpTaxRegulation            tmpTaxRegulation;
;

ttsbegin;
purchTable  = PurchTable::find( 'XYZ');
purchTotalsSet = PurchTotals::newPurchTable(purchTable);
purchTotalsSet.calc();

taxRegulation = TaxRegulation::newTaxRegulation(purchTotalsSet.tax(), null);

tmpTaxRegulation = taxRegulation.tmpTaxRegulation();

while select tmpTaxRegulation
    where tmpTaxRegulation.TaxCode == CustomTable.TaxCode
{
    tmpTaxRegulation.SourceRegulateAmountCur = 2;
    tmpTaxRegulation.update();
}

taxRegulation.saveTaxRegulation();

ttscommit;
}

and for lines 

//for line
void createPOLinesSalesTax(PurchLine _purchLine, POLinesTaxIntegrationLog poLinesSalesTaxLog)
{
    PurchTotals                             purchTotalsSet;
    TaxRegulation                           taxRegulation;
    TmpTaxWorkTrans                         tmpTaxWorkTrans;
    TmpTaxRegulation                        tmpTaxRegulation;
    PurchTable                              purchTable;
    TaxAmountCur                            taxAmountCur;
    ;

    purchTable = PurchTable::find('XYZ');

    ttsbegin;

    purchTotalsSet = PurchTotals::newPurchTable(purchTable);
    purchTotalsSet.calc();
    purchTotalsSet.tax().sourceSingleLine(true, true);
    taxAmountCur = purchTotalsSet.tax().totalTaxAmountSingleLine(_purchLine.TableId, _purchLine.RecId, true);

    taxRegulation = TaxRegulation::newTaxRegulation(purchTotalsSet.tax(), null);

    tmpTaxRegulation = taxRegulation.tmpTaxRegulation();

    while select tmpTaxRegulation
        where tmpTaxRegulation.TaxCode == poLinesSalesTaxLog.TaxCode
    {
        tmpTaxRegulation.SourceRegulateAmountCur = taxAmountCur;
        tmpTaxRegulation.update();
    }

    taxRegulation.saveTaxRegulation();

    ttscommit;

Issue is that above code sets value in Adjusted amount, but I want tax value on sales tax amount column in  below screen.

pastedimage1655886051748v1.png

I tried to update value in tmpTaxRegulation.SourceTaxAmountCur column but it throws error. cannot edit a record in Tax Trans (TmpTaxTrans). The record has never been selected.

Kinldy help me to sort it out..

I have the same question (0)

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... 661 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 620

#3
Subra Profile Picture

Subra 473

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans