BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Bug]: Subcontracting: SetIsSubcontracting calls CurrPage.Update() with SaveRecord = true from OnAfterGetCurrRecord, aborting the Transfer Order page

Open Subhavarman opened this issue 2 months ago • 11 comments

Describe the issue

On the Transfer Order page, Subc. Trans. Order Sub. (PageExtension 20529) forces a saving page update from inside a record-fetch trigger. That aborts the page during the normal transfer document flow.

The statement

https://github.com/microsoft/BCApps/blob/1a7e9d7b07f85189c2f6809b97f6faf40d9ba34f/src/Apps/W1/Subcontracting/App/src/Transfer/SubcTransOrderSub.PageExt.al#L179-L183

internal procedure SetIsSubcontracting(IsSubcontractingRelated: Boolean)
begin
    HasSubcontractingContext := IsSubcontractingRelated;
    CurrPage.Update();          // SaveRecord defaults to true
end;

CurrPage.Update() with no argument is CurrPage.Update(true), so it saves the record. The procedure only assigns a visibility Boolean, so there is nothing that needs saving.

The caller

https://github.com/microsoft/BCApps/blob/1a7e9d7b07f85189c2f6809b97f6faf40d9ba34f/src/Apps/W1/Subcontracting/App/src/Transfer/SubcTransferOrder.PageExt.al#L98-L107

trigger OnAfterGetCurrRecord()
begin
#if not CLEAN29
    if not SubcontractingEnabled then
        exit;

#endif
    ShowSubcontractingFactBox := SubcTransferManagement.IsSubcontractingTransferDocument(Rec);
    CurrPage.TransferLines.Page.SetIsSubcontracting(ShowSubcontractingFactBox);
end;

OnAfterGetCurrRecord fires on every current-record refresh, including moments when the subform line is not in a clean committed state. The forced save then fails in one of two ways:

  • Brand-new subform line, Line No. not yet assigned. The platform resolves the save as a rename, which reaches Table 5741 "Transfer Line".OnRename - an unconditional Error. A Transfer Line can never be renamed, so the abort is guaranteed.
  • Existing line whose page copy is older than the stored record. Optimistic concurrency rejects the write.

Observed errors

Business Central 29.0.54011, India (IN) localisation, clean sandbox, no third-party extensions installed.

Variant A - uncommitted line:

You cannot rename a Transfer Line
Microsoft.Dynamics.Nav.Runtime.FormAbortException: Page Transfer Order has to close

Variant B - committed line, stale page copy:

The changes to the Transfer Line record cannot be saved because some information on the
page is not up-to-date. Close the page, reopen it, and try again.
Identification fields and values: Document No.='1006', Line No.='10000'

Call stack

Copied from the client's Share details pane. Identical for both variants, two frames, both in this extension.

"Subc. Trans. Order Sub."(PageExtension 20529).SetIsSubcontracting line 3
  - Subcontracting by Microsoft version 29.0.54011.54955
"Subc. Transfer Order"(PageExtension 20526).OnAfterGetCurrRecord(Trigger) line 8
  - Subcontracting by Microsoft version 29.0.54011.54955

SetIsSubcontracting line 3 is the CurrPage.Update() statement. The trigger's reported line 8 does not line up with line 8 of the source above because the #if not CLEAN29 directives are compiled out of the shipped artifact; line 8 in the compiled object is the SetIsSubcontracting call.

Image

IN localisation, no third-party extensions. Release itself succeeded here and the failure landed on the next action, which is why we say the trigger, not the action, is the cause.

One more observation

The subform's own OnAfterGetCurrRecord guards itself against repeated work:

local procedure SetSubcontractingVisibility()
begin
    if Rec."Document No." = TransferHeader."No." then
        exit;

The call arriving from the parent page has no equivalent guard, so SetIsSubcontracting and its forced save run on every refresh.

Expected behavior

Adding a line to a Transfer Order and then invoking Release, or Create Whse. Shipment, should complete normally: the order is released and the warehouse shipment is created. No extension should force a saving page update from a record-fetch trigger.

SetIsSubcontracting assigns a visibility Boolean and nothing else, so it should refresh the page without writing the record:

 internal procedure SetIsSubcontracting(IsSubcontractingRelated: Boolean)
 begin
     HasSubcontractingContext := IsSubcontractingRelated;
-    CurrPage.Update();
+    CurrPage.Update(false);
 end;

CurrPage.Update(false) redraws the page and re-evaluates the Visible properties bound to HasSubcontractingContext, which is all this procedure needs. It cannot trigger a write, so neither failure mode can occur.

Steps to reproduce

About two minutes. No item tracking, no extensions, no special configuration.

  1. Provision a Business Central 29.0.54011 sandbox on the IN (India) localisation, standard CRONUS, with no third-party apps installed.
  2. Open Transfer Orders and choose New.
  3. Set Transfer-from Code, Transfer-to Code and In-Transit Code. On CRONUS IN: EAST, WEST, OUT. LOG.
  4. On the lines subform, enter an Item No. (for example 1896-S) and Quantity 10.
  5. Without changing focus after typing the quantity, click Release.
  6. Then click Create Whse. Shipment.

The error appears at step 5 or step 6. Which one you get depends only on whether the subform line had already been committed when the trigger fired; both come from the same code path and produce the same call stack.

Tested on artifacts 29.0.54011.54884, .54955, .55000 and .55007. Present on IN in all of them, including the newest.

Additional context

Why it surfaces only on IN

We ran the same automated suite of 1435 tests twice from one pipeline, minutes apart, against the same artifact sandbox/29.0.54011.55007, with the localisation as the only difference:

Localisation Result
W1 / base 1435 tests, 0 failures
IN 1435 tests, 6 failures - every one with the error and call stack above

Same split on artifact .54884. We also reproduced it by hand in the web client on IN and confirmed it passing on W1, using byte-identical BC Page Scripting recordings that create every object they touch, which rules out demo data and configuration.

Image

W1 / base. The same two recordings, byte for byte, complete without errors.

The Subcontracting app is installed on both localisations - on W1 it is listed in Extension Management as published Global and installed - so the presence of the app is not the discriminator.

Our reading of the gate

The likely gate is the #if not CLEAN29 guard in PageExtension 20526:

#if not CLEAN29
    if not SubcontractingEnabled then
        exit;
#endif

SubcontractingEnabled comes from Subc. Feature Flag Handler.IsSubcontractingEnabled(), which returns not ManufacturingSetup."Legacy Subcontracting". So on a company where Legacy Subcontracting is still on, the trigger exits at the guard and the bug is invisible; where it is off, the forced save runs. That would make this a demo-data difference rather than localised code.

We have not confirmed the flag's value on each localisation, so please treat that as our reading rather than as established.

It also means the guard disappears entirely once CLEAN29 is defined, at which point the forced save runs unconditionally on every localisation.

Attached: the Page Scripting recordings

I have attached the two BC Page Scripting recordings we used - 00_Repro_Setup.yml 01_Repro_R1_Release.yml

File What it does
00_Repro_Setup.yml Creates everything the repro needs, from base functionality only: an item tracking code, an item, and three locations (from, to, and in-transit). Run once per container.
01_Repro_R1_Release.yml Creates the transfer order and its line, invokes Release and then Create Whse. Shipment, and validates the resulting warehouse shipment line.

Both use base objects only and create every object they touch, so the same two files run unchanged on any localisation with no demo-data dependency. Import them through the Page Scripting pane in the web client (Preview feature) and replay.

On IN the second script stops at Release or at Create Whse. Shipment. On W1 it runs to the end with every validation passing. That is the comparison shown in the two screenshots above.

Impact

Releasing a transfer order and creating its warehouse shipment is core inventory functionality, and this reproduces with a stock item, stock locations, no item tracking and no extensions, so it is not configuration-dependent. It also breaks any partner or ISV extension that drives the Transfer Order page on an affected company.

We have the two BC Page Scripting .yml recordings that reproduce it in a single run, plus the full client error details including session and activity IDs. Happy to attach any of it on request.

I will provide a fix for a bug

  • [ ] I will provide a fix for a bug

Subhavarman avatar Sep 29 '26 10:09 Subhavarman

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

JesperSchulz avatar Oct 01 '26 10:10 JesperSchulz

Checking in on this one. The triage report went up for product-group validation on 1 October and I don't think there's been a response since.

This is no longer a preview-only concern. Now that BC v29 is live, our CI pipeline runs against the current version, and our extensions that drive the Transfer Order page fail there on the India localisation — the automated tests covering that flow abort before any assertion runs, because the page aborts first. It is a blocker for us.

Current state from the outside, as of today:

  • CurrPage.Update() in SetIsSubcontracting is unchanged on main (commit 7ce3ab9c).
  • Still reproduces on every artifact we have tested: 29.0.54011.54884, .54955, .55000 and .55007.

Could I get a status on two things?

  1. Has the defect been accepted, and is there a target version? We need that to plan India-localisation readiness, and right now releasing a Transfer Order is blocked on every artifact we have tried.

  2. Is there a supported workaround in the meantime? Anything that avoids the saving page update from OnAfterGetCurrRecord would unblock us.

From the outside it looks like a single argument on CurrPage.Update(), since the procedure only assigns a visibility Boolean — so hopefully a cheap one for the team to pick up. If a partner contribution is the faster route here, let me know and I will look into what that would take on our side.

Happy to supply whatever else would help. I still have the full client session and activity IDs, and I can re-run the attached Page Scripting recordings against any artifact you want to name.

cc @JesperSchulz, since you kicked off the triage.

Subhavarman avatar Oct 13 '26 06:10 Subhavarman

I will ping the owning team! Sorry about the delay.

JesperSchulz avatar Oct 13 '26 08:10 JesperSchulz

Coverage: issue-only analysis of microsoft/BCApps#12063; no code change reviewed; no implementation or fix proposed; repository evidence searched: local BCApps W1 Subcontracting app and test app (SetIsSubcontracting callers, page extension source, Transfer-folder history); not covered: no DME or test-history search, no country-folder search outside src/Apps, no runtime run.

BC impact analysis

Affected areas

  • Inventory / Transfer Orders
  • Warehouse
  • Subcontracting

Reported severity and reproducibility: Blocking error on Release or Create Whse. Shipment. Reproducibility is specific and actionable. Runtime reproduction was not performed here.

Customer-facing behavior: Release or Create Whse. Shipment fails with a page abort. The reporter expects the order to release and the warehouse shipment to be created.

Existing tests

  • None identified
  • Test codeunits identified: None identified

Affected E2E scenarios

  • Transfer order release: the page aborts during refresh before Release finishes.
  • Warehouse shipment from a transfer order: the abort occurs on the next action.

Existing tests for affected E2E scenarios

  • None identified
  • E2E test codeunits identified: None identified

Localizations impacted: Not assessed (IN potentially impacted; the IN/W1 difference is unconfirmed)

First-party apps impacted: Subcontracting

Potentially impacted first-party apps: None identified

Recommendation: Recommend: Approve - The report is specific, reproducible and affects a core flow. No duplicate or by-design evidence was found, and the problem is confined to the Subcontracting app. The cause of the IN/W1 difference is unconfirmed.

Suggested test buckets to run in DME

  • Buckets: none resolved
  • Unmapped / needs manual bucket assignment: no existing tests identified

A full regression and impact analysis was generated by scm-impact-agent.

PredragMaricic avatar Oct 13 '26 09:10 PredragMaricic

@JesperSchulz @PredragMaricic — a month on from the Approved label, the issue is still unassigned and CurrPage.Update() in SetIsSubcontracting is unchanged on main. Is there an owner or a target version yet?

In the meantime I have retested on the current build, and I need to correct something I said in the original report.

Matched pair on the current build

Two Docker sandboxes built from the same artifact version, 29.0.54011.57368, one IN and one W1. Subcontracting 29.0.54011.57368 published and installed in both. No partner extensions in either. Identical Page Scripting recording in both — the one attached to this issue, which creates every object it touches, so there is no demo-data dependency.

Artifact Apps installed Result of 01_Repro_R1_Release
sandbox/29.0.54011.57368/in 144, all published by Microsoft fails
sandbox/29.0.54011.57368/base 86 Microsoft apps passes

The failure on IN:

The changes to the Transfer Line record cannot be saved because some information on the page is not up-to-date. Close the page, reopen it, and try again.

Identification fields and values: Document No.='1004', Line No.='10000'

Same failure as originally reported, on the newest artifact available, with the build version held constant across the two runs.

Correction: Legacy Subcontracting is not the discriminator

In the original report I suggested the IN/W1 split was explained by Manufacturing Setup."Legacy Subcontracting" gating the #if not CLEAN29 guard in PageExtension 20526. I flagged it as our reading rather than an established fact. It is wrong, and I would rather withdraw it than have someone spend time on it.

I read the field directly from the tenant databases of both containers above:

Artifact Company Legacy Subcontracting
…57368/in CRONUS IN 0
…57368/in My Company 0
…57368/base CRONUS International Ltd. 0

0 in every company of both, and in the client the toggle is greyed out and not editable. So Subc. Feature Flag Handler.IsSubcontractingEnabled() returns true on both localisations, the guard does not exit on either, and SetIsSubcontracting — together with its forced save — executes on W1 exactly as it does on IN.

Why that raises the severity rather than lowering it

If the code path executes identically on both, this is not an India-specific defect and not a demo-data difference. The unsafe write runs on every localisation. IN reaches a state where the save actually conflicts; stock W1 happens not to. Anything else that leaves the Transfer Line subform record out of step with the stored record — another localisation, a partner extension, a different order of user input — can surface the same abort on W1.

So the defect is still the one in the title: a saving CurrPage.Update() issued from inside OnAfterGetCurrRecord, in a procedure whose only other statement assigns a visibility Boolean.

internal procedure SetIsSubcontracting(IsSubcontractingRelated: Boolean)
begin
    HasSubcontractingContext := IsSubcontractingRelated;
    CurrPage.Update();          // SaveRecord defaults to true
end;

CurrPage.Update(false) redraws the page and re-evaluates the Visible properties bound to HasSubcontractingContext, which is everything this procedure needs, and cannot write.

I am not claiming to know why IN reaches the conflicting state and W1 does not — that needs someone with the localisation source in front of them. But that is a second-order question. Whatever the answer, the forced save should not be there on any localisation.

On "Existing tests: none identified"

Agreed, and that is presumably what let it through. The two Page Scripting recordings attached to this issue cover the flow end to end using base objects only and create every object they touch, so they run unchanged on any localisation. Please feel free to use them as the basis for a regression test, or name an artifact and I will re-run them against it and post the result here.

Where this leaves us

BC v29 is live. Our CI runs against the current version, our extensions drive the Transfer Order page, and the India jobs have stayed red on every artifact we have tested, up to and including .57368. Releasing a transfer order and creating its warehouse shipment is core inventory functionality, and it reproduces with a stock item, stock locations, no item tracking and no partner extensions. It is a blocker for us.

Happy to supply anything else that would help — full client error details with session and activity IDs, or a run against any artifact you want to name.

Subhavarman avatar Nov 04 '26 06:11 Subhavarman

Hi ! I'd like to take this. Pull request coming shortly.

Franco111000 avatar Nov 16 '26 09:11 Franco111000

Thank you both — @Franco111000 for picking this up and @JesperSchulz for merging it. PR #14122 looks like exactly the right change.

@Franco111000 you asked the reporter to verify it on India, so I ran our ATDD suite against a v30 insider artifact. It still fails, and I would like help working out why.

What I ran

Stage Artifact Artifact published Result
NextMajor, IN sandbox/30.0.58454.0/in 2026-11-18 09:05 UTC 6 failures
NextMinor, IN sandbox/29.2.58453.0/in 2026-11-18 6 failures

PR #14122 merged to main at 2026-11-17 10:41 UTC, so the v30 artifact above was published 22 hours later.

The NextMinor result is expected — that is a v29 artifact and releases/29.x is unchanged (see below). The v30 result is the one I cannot explain.

Failures are identical to the original report, all six in codeunit 71422591:

The changes to the Transfer Line record cannot be saved because some information on the page
is not up-to-date. Close the page, reopen it, and try again.
Identification fields and values: Document No.='1004',Line No.='10000'

Two questions

1. Has the fix actually reached the insider artifacts yet?

This is my first guess, and if so there is nothing to investigate — I just tested too early. If you can tell me which artifact build number first contains the change, I will re-run against it and post the result.

2. If it has reached them, is the fix complete?

You noted in the PR that the app has two other CurrPage.Update() calls which you left alone, on the grounds that they run after the user's own validate or action. If SetIsSubcontracting is now CurrPage.Update(false) in the artifact I tested, then the forced save that aborts the page is coming from somewhere else, and one of those two would be the obvious next place to look.

I cannot tell these two apart from outside the build system, which is why I am asking rather than asserting.

And please could releases/29.x still be backported?

Checked today, the fix is on main only:

Branch SetIsSubcontracting
main CurrPage.Update(false)
releases/29.x CurrPage.Update()
releases/29.1 CurrPage.Update()

v29 is the version live in production and the version our CI runs against, so wherever the v30 question lands, the current release still needs this. Releasing a transfer order from the page is broken there today.

Earlier evidence, for completeness

On the unfixed code (2026-11-04): two containers from the same artifact version 29.0.54011.57368, one IN and one W1, no partner extensions in either, same Page Scripting recording — IN failed, W1 passed, with the build version held constant. That also disproved our original Legacy Subcontracting theory, which we withdrew above.

Happy to run whatever would help. Name an artifact and I will test it.

Subhavarman avatar Nov 18 '26 11:11 Subhavarman

Thanks for testing it so quickly! I think the fix just isn't in that build yet. I opened the Subcontracting app inside 30.0.58454.0, and SetIsSubcontracting there still has CurrPage.Update();. The PR merged at 13:08 UTC on the 17th, so that build came too early. Any newer artifact can be checked the same way before running the suite.

The two other CurrPage.Update() calls are on the Work Center Card and the Subcontractor Prices page, so they can't save a Transfer Line. I wouldn't look there.

On 29.x: agreed, it has the same line. If the maintainers want the backport, I'm happy to open it against releases/29.x.

Franco111000 avatar Nov 18 '26 13:11 Franco111000

@Franco111000 that settles it — thank you for checking inside the artifact. We tested too early, and the leftover CurrPage.Update() calls being on the Work Center Card and Subcontractor Prices pages rules out my second theory cleanly.

Opening the app in the artifact before running the suite is a much better loop than waiting an hour on a pipeline to find out. We will do that from now on. 30.0.58454.0 is still the newest v30 IN artifact as I write this, so there is nothing newer to check yet. I will re-run the suite against the first artifact that carries the change and post the result here either way.

On the backport — yes please, that would help us a great deal. @JesperSchulz would you be happy for @Franco111000 to open it against releases/29.x? v29 is the version live in production and the one our CI runs against, so until the fix lands there, releasing a transfer order from the page stays broken for us on the current release. releases/29.x and releases/29.1 both still have the original line as of today.

Subhavarman avatar Nov 18 '26 13:11 Subhavarman

Yes, please, @Franco111000. Please open a PR against releases/29.x with the same one-line SetIsSubcontracting change from #14122 and link it here. Thanks, @Subhavarman, for offering to rerun the India tests once you have an artifact containing the fix. We can keep this issue closed for the main fix and track the backport in its PR; we don’t have a confirmed release build yet.

JesperSchulz avatar Nov 18 '26 13:11 JesperSchulz

Backport is up: #14291

Franco111000 avatar Nov 18 '26 15:11 Franco111000