Skip to main content

Notifications

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

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Product updates

Dynamics 365 release plans