Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

AL Extension to set manual tax amount on Purchase Invoice

Posted on by 8
Hi,
I'm importing, via web services, a bunch of historical PurchaseInvoice data into BC from another accounting system.  The data has, for whatever reason, many PurchaseInvoice lines where the tax amount is basically manually entered.  So that means the imported data can not be setup to use the built-in tax setups in BC.
There is a process in BC to manually override the tax in the user interface:
 
I'm looking to be able to do this using an AL extension and webservice.
 
The video shows that ultimately the user is modifying the PurchaseLine.Tax% field.  I have verified this by inspecting the page and viewing the PurchaseLine table and seeing the resulting value in the "Tax %" column.
 
The issue is that the "PurchaseLine.Tax %" field can not be added to the UI (it doesn't show up in the "Purchase Invoice > Lines > then "Help" > Inspect Page > Table Fields listing).
 
I also tried "Settings > Personalize > Lines > Add Field" but the "Tax%" field does not show up there either.
 
Similarly, in AL Extension code, creating a new extended card for PurchaseLine2 to show the field for "Tax%" results in a compile error:
 
 
Curious thing is that the webservices for PurchaseLines like:
https://api.businesscentral.dynamics.com/v2.0/xxxxxxxx/xxxxxxxxxx/ODataV4/Company('xxxxxxxxxxxx')/BLXPurchaseInvoiceLinesV2(xxxxxxxxxxx)
Shows the "taxPercent" field in the JSON results.
 
However if you try to post to that endpoint then you get an error:
"'POST' requests for 'BLXPurchaseInvoiceLinesV2' of EdmType 'Entity' are not allowed within Dynamics 365 Business Central OData web services."
 
So, I'm kinda stuck.  The field "Tax %" definitely exists on Purchase Line table.  But how can I access it and modify it? Ideally through an AL extension.
 
Thank you for your help with this.
Thanks!
Alex.
 
 
 
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 63,463 Super User on at
    AL Extension to set manual tax amount on Purchase Invoice
    This is quite complicated. I have experienced similar development before, and the processing of W1 is different from that of US. You can refer to the standard code. The main points are the following three points. If I have time I might discuss this on my blog later.
            TempVATAmountLine: Record "VAT Amount Line" temporary;
            SalesTaxCalculate: Codeunit "Sales Tax Calculate";
            TempSalesTaxAmtLine: Record "Sales Tax Amount Line" temporary;
     
     
    Thanks
    ZHU
  • CU29062212-0 Profile Picture
    CU29062212-0 8 on at
    AL Extension to set manual tax amount on Purchase Invoice
    Hi YUN ZHU,
     
    Your hint of looking for "VAT %" helped with this.  I had been looking for "Tax %", but that is, I guess, the localized field name.  Instead I needed to be looking for "VAT %".
     
    Do you know how to write a simple codeunit that accesses the SalesTaxLines to be able to modify the field "Tax Amount":
     
    Thank you.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 63,463 Super User on at
    AL Extension to set manual tax amount on Purchase Invoice
    Can you find this field in the Source Table? For example, in the W1 version, this field is not editable.
     
    Thanks.
    ZHU
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 4,607 Super User on at
    AL Extension to set manual tax amount on Purchase Invoice
    Hi
    What message do you get when you position above the field in VSC?
    Does that field belong to any extension? Isn't it an "internal" one?
    BR
    GR
  • CU29062212-0 Profile Picture
    CU29062212-0 8 on at
    AL Extension to set manual tax amount on Purchase Invoice
    Hi,
    I appreciate the responses, but they don't answer the question.  Here is the PageType=API extension:
     
     
    You can see the "Tax %" field shows as an error in Visual Studio Code.  This means the field is not accessible for some reason.  Even though the field does exist on the table (see highlighted field in the BC "View Table" screen:
     
    How do I get this field to be accessible as a VSCode extension, or some other way?
     
    Thanks
    Alex.
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 63,463 Super User on at
    AL Extension to set manual tax amount on Purchase Invoice
    Use Page Extension to add it to the page. If you have the new version, you can try the following method.
    Business Central 2023 wave 2 (BC23): Add existing table fields to optimize your pages (Adding Table Fields to Page without Page Extensions)
     
    In addition, it is usually more convenient to import this data using Configuration Package rather than Web Service.
    Microsoft Dynamics 365 Business Central: How to Export and Import Data (Using Configuration Packages)
     
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 4,607 Super User on at

Helpful resources

Quick Links

First Dynamics 365 Community Call (CRM Edition)

Don't miss the first D365 Community Call on 7/10!

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 285,557 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,484 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans