Skip to content

Update expense VAT specification source - #10312

Merged
Alexander Yakunin (Alexander-Ya) merged 40 commits into
mainfrom
bugs/Update-Expense-VAT-Specification-Source
Aug 31, 2026
Merged

Update expense VAT specification source#10312
Alexander Yakunin (Alexander-Ya) merged 40 commits into
mainfrom
bugs/Update-Expense-VAT-Specification-Source

Conversation

@Alexander-Ya

@Alexander-Ya Alexander Yakunin (Alexander-Ya) commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces several important changes to the Expense Agent application, focusing on enforcing stricter controls over the creation and modification of VAT specification records, improving data integrity, and enhancing error handling and reporting. The changes ensure that records created via the Expense Agent API are clearly distinguished and protected from modification, and that error messages during expense report posting are more informative and actionable.

Key changes include:

1. Enforcing Source-based Controls and Data Integrity

  • Added logic to set the Source field to Agent when VAT specifications are created via the API, and to Manual when created through the UI. This distinction is enforced in both the API and page triggers (OnNewRecord, OnInsertRecord). [1] [2]
  • Made the Source field non-editable and added system metadata classification in the Expense VAT Specification table.
  • Added validation logic throughout the Expense VAT Specification table to skip certain field validations and calculations if the Source is Agent, ensuring agent-created records are handled differently from manual entries. [1] [2] [3] [4] [5] [6] [7]

2. Preventing Unauthorized Modifications

  • Introduced triggers to block modifications and deletions of VAT specification records created by the Expense Agent API, with clear error messages. [1] [2]
  • Updated the UpdateVATSpecification procedure to prevent overwriting or deleting agent-created VAT specification lines, enforcing immutability for API-generated records.

3. Expense VAT Specification Generation and Categorization

  • Improved logic for generating VAT specification lines, ensuring that manual and agent-created lines are handled separately and that the correct Source is set during creation. [1] [2]
  • Ensured that the correct category and subcategory fields are validated and set only for manual entries, not for agent-created lines. [1] [2] [3]

4. Enhanced Error Handling and User Feedback

  • Improved error reporting during expense report posting by introducing more specific error messages and navigation actions when VAT reclaim status is pending, making it easier for users to resolve issues. [1] [2]
  • Added a helper procedure to generate detailed ErrorInfo objects for pending VAT reclaim statuses, including navigation actions for user convenience.

5. Miscellaneous Improvements

  • Ensured that string values (e.g., Expense Location) are properly truncated to fit field length constraints, preventing data errors.
  • When creating expense report lines from VAT specs, now copies currency code and factor from the expense, and updates reimbursement amounts for accuracy. [1] [2]
  • Adjusted rounding difference logic to handle both amount and local currency amount, improving accuracy in posting. [1] [2]

These changes collectively improve the robustness, security, and usability of the Expense Agent's VAT specification handling and expense report posting workflows.<!--
Thanks for contributing to BCApps!

A few things before you hit "Create pull request":

  • Your PR must link to an approved issue. New here? See CONTRIBUTING.md.
  • You must have built and run your change yourself. CI is a safety net, not a substitute.
  • If you used AI or an agent to write this PR, you are still the author. Read the diff,
    build it, and try it before requesting review.

Contributing guide: https://github.com/microsoft/BCApps/blob/main/CONTRIBUTING.md
Local dev environment: https://github.com/microsoft/BCApps/blob/main/LOCAL_DEV_ENV.md
-->

What & why

Linked work

Fixes AB#626087

How I validated this

  • I read the full diff and it contains only changes I intended.
  • I built the affected app(s) locally with no new analyzer warnings.
  • I ran the change in Business Central and confirmed it behaves as expected.
  • I added or updated tests for the new behavior, or explained below why none are needed.

What I tested and the outcome (required — be specific: scenarios, commands, screenshots for UI changes)

Risk & compatibility

@github-actions github-actions Bot added the AL: Apps (W1) Add-on apps for W1 label Aug 17, 2026
@Alexander-Ya Alexander Yakunin (Alexander-Ya) changed the title Update expense VAt specification source Update expense VAT specification source Aug 17, 2026
@github-actions github-actions Bot added the Team: Integrations GitHub request for Integrations area label Aug 17, 2026
Comment thread src/Apps/W1/ExpenseAgent/app/src/ExpenseReport/Pages/ExpenseReport.Page.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/Expense/Tables/Expense.Table.al
@github-actions

This comment was marked as resolved.

Comment thread src/Apps/W1/ExpenseAgent/app/src/Expense/Tables/Expense.Table.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/APIs/ExpenseVATSpecAPI.Page.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/ExpenseReport/Pages/ExpenseReport.Page.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/Expense/Pages/ExpenseVATSpecification.Page.al Outdated
@github-actions

This comment was marked as resolved.

Comment thread src/Apps/W1/ExpenseAgent/app/src/APIs/ExpenseVATSpecAPI.Page.al Outdated
@github-actions

This comment was marked as outdated.

Comment thread src/Apps/W1/ExpenseAgent/app/src/ExpenseReport/Pages/ExpenseReport.Page.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/Common/Enums/ExpenseVATSpecSource.Enum.al Outdated
Comment thread src/Apps/W1/ExpenseAgent/app/src/Common/Enums/ExpenseVATSpecSource.Enum.al Outdated
@alexei-dobriansky

This comment was marked as spam.

@alexei-dobriansky

This comment was marked as spam.

@mynjj Joshua (mynjj) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider hardening the upgrade

Merged via the queue into main with commit f3db89e Aug 31, 2026
334 of 336 checks passed
@Alexander-Ya
Alexander Yakunin (Alexander-Ya) deleted the bugs/Update-Expense-VAT-Specification-Source branch August 31, 2026 07:40
Alexander Yakunin (Alexander-Ya) added a commit that referenced this pull request Sep 1, 2026
This pull request backports #10312 to releases/29.x

Fixes
[AB#648452](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/648452)

---------

Co-authored-by: Claudiu Ciumedean <cciumedean@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI pushed a commit that referenced this pull request Sep 2, 2026
This pull request introduces several important changes to the Expense
Agent application, focusing on enforcing stricter controls over the
creation and modification of VAT specification records, improving data
integrity, and enhancing error handling and reporting. The changes
ensure that records created via the Expense Agent API are clearly
distinguished and protected from modification, and that error messages
during expense report posting are more informative and actionable.

**Key changes include:**

* Added logic to set the `Source` field to `Agent` when VAT
specifications are created via the API, and to `Manual` when created
through the UI. This distinction is enforced in both the API and page
triggers (`OnNewRecord`, `OnInsertRecord`).
[[1]](diffhunk://#diff-bb08e5737d916802a07fe0b53c9e007bba3dcd3849e39a1b1c998b9adf10c672R108-R131)
[[2]](diffhunk://#diff-9262d4cc9dead274e2f614199b52dab823f01302d8cb8886ef3d593db9924ffbR69-R74)
* Made the `Source` field non-editable and added system metadata
classification in the `Expense VAT Specification` table.
* Added validation logic throughout the `Expense VAT Specification`
table to skip certain field validations and calculations if the `Source`
is `Agent`, ensuring agent-created records are handled differently from
manual entries.
[[1]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R37-R43)
[[2]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R62-R70)
[[3]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R98)
[[4]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R159-R170)
[[5]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R182)
[[6]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R193)
[[7]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R206-R208)

* Introduced triggers to block modifications and deletions of VAT
specification records created by the Expense Agent API, with clear error
messages.
[[1]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R264-R281)
[[2]](diffhunk://#diff-242f0f782d0eaacabf61a7043b9b871c54d90db8d36abd1a0d5e8cc53d4c2036R791)
* Updated the `UpdateVATSpecification` procedure to prevent overwriting
or deleting agent-created VAT specification lines, enforcing
immutability for API-generated records.

* Improved logic for generating VAT specification lines, ensuring that
manual and agent-created lines are handled separately and that the
correct `Source` is set during creation.
[[1]](diffhunk://#diff-242f0f782d0eaacabf61a7043b9b871c54d90db8d36abd1a0d5e8cc53d4c2036L1334-R1347)
[[2]](diffhunk://#diff-242f0f782d0eaacabf61a7043b9b871c54d90db8d36abd1a0d5e8cc53d4c2036R1358-R1375)
* Ensured that the correct category and subcategory fields are validated
and set only for manual entries, not for agent-created lines.
[[1]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R37-R43)
[[2]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R182)
[[3]](diffhunk://#diff-975ae126b7573570554253f501e44ef04cc551aae729dffb01d849f6ef47e0e4R206-R208)

* Improved error reporting during expense report posting by introducing
more specific error messages and navigation actions when VAT reclaim
status is pending, making it easier for users to resolve issues.
[[1]](diffhunk://#diff-8e8ca750ce38e56ef3c6273fd62f5334be1c20ab032f988c1e7db28b32b8e642R74-R76)
[[2]](diffhunk://#diff-8e8ca750ce38e56ef3c6273fd62f5334be1c20ab032f988c1e7db28b32b8e642L247-R267)
* Added a helper procedure to generate detailed `ErrorInfo` objects for
pending VAT reclaim statuses, including navigation actions for user
convenience.

* Ensured that string values (e.g., `Expense Location`) are properly
truncated to fit field length constraints, preventing data errors.
* When creating expense report lines from VAT specs, now copies currency
code and factor from the expense, and updates reimbursement amounts for
accuracy.
[[1]](diffhunk://#diff-f396a74c30e7dd3192138ba8ce28f30e32d62301e595bf6475d527b52dae60e7R330-R331)
[[2]](diffhunk://#diff-f396a74c30e7dd3192138ba8ce28f30e32d62301e595bf6475d527b52dae60e7R345)
* Adjusted rounding difference logic to handle both amount and local
currency amount, improving accuracy in posting.
[[1]](diffhunk://#diff-8e8ca750ce38e56ef3c6273fd62f5334be1c20ab032f988c1e7db28b32b8e642L431-R448)
[[2]](diffhunk://#diff-8e8ca750ce38e56ef3c6273fd62f5334be1c20ab032f988c1e7db28b32b8e642L474-R495)

These changes collectively improve the robustness, security, and
usability of the Expense Agent's VAT specification handling and expense
report posting workflows.<!--
Thanks for contributing to BCApps!

A few things before you hit "Create pull request":
- Your PR must link to an approved issue. New here? See CONTRIBUTING.md.
- You must have built and run your change yourself. CI is a safety net,
not a substitute.
- If you used AI or an agent to write this PR, you are still the author.
Read the diff,
  build it, and try it before requesting review.

Contributing guide:
https://github.com/microsoft/BCApps/blob/main/CONTRIBUTING.md
Local dev environment:
https://github.com/microsoft/BCApps/blob/main/LOCAL_DEV_ENV.md
-->

<!-- A few sentences: what does this change do, and what problem does it
solve? -->

<!-- Required: link an approved GitHub issue using "Fixes #<number>".
Microsoft contributors: also link the ADO work item with "AB#<number>"
if you have one. -->

Fixes
[AB#626087](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/626087)

- [x] I read the full diff and it contains only changes I intended.
- [x] I built the affected app(s) locally with no new analyzer warnings.
- [x] I ran the change in Business Central and confirmed it behaves as
expected.
- [x] I added or updated tests for the new behavior, or explained below
why none are needed.

**What I tested and the outcome** *(required — be specific: scenarios,
commands, screenshots for UI changes)*

<!-- Example:
- Ran the new "Post and Send" action on a sales invoice in a fresh
container; document posted and email queued (see screenshot).
- New unit tests in MyFeatureTest.Codeunit.al pass locally; full module
test suite green.
- No tests added because change is comment-only / refactor with existing
coverage. -->

<!-- Anything reviewers should watch for: breaking changes, upgrade/data
impact, permissions,
telemetry, feature flags, follow-up work. Write "None" if there's
nothing to call out. -->

---------

Co-authored-by: Claudiu Ciumedean <cciumedean@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit aebad9c)

Co-authored-by: Alexander-Ya <179119309+Alexander-Ya@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 ExpenseManagement Team: Integrations GitHub request for Integrations area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants