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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans