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

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Sales Order Subform Conditional ShowMandatory

(0) ShareShare
ReportReport
Posted on by 573
Trying to add a procedure that will determine if the Location Code field on the Sales Order Subform should show as Mandatory based on the Sales Line Item and Item.Type.  Works fine for the Item being entered, but then also updates the setting for ALL items in the Subform based on the current record.  Below is the procedure that I am calling from the OnAfterValidate trigger of the No. field in the Subform.  I only want it to change the boolean value on the line being modified.
 
What am I missing? Is there a way to do that? Visual below.  Before the last line item was entered, the 2nd-4th lines did not show the asterisk, the 5th line should have the fields mandatory, when the Item was entered, all the lines changed.
 
modify("No.")
        {
            trigger OnAfterValidate()
            begin
                ShowMandatoryResults()
            end;
        }
 
        modify("Location Code")
        {
            ShowMandatory = ShowMandatoryValue;
        }
 
    procedure ShowMandatoryResults()
    begin
        SalesLine.SetRange("Document Type", SalesDocumentType::Order);
        SalesLine.SetRange("Document No.", Rec."Document No.");
        SalesLine.SetRange("Line No.", Rec."Line No.");
        if SalesLine.FindSet() then begin
            If SalesLine.Type <> SalesLineType::Item then
                exit
            else begin
                Item.SetRange("No.", SalesLine."No.");
                Item.SetRange(Type, ItemType::Inventory);
                if Item.FindSet() then
                    ShowMandatoryValue := true
                else
                    ShowMandatoryValue := false;
            end;
        end;
    end;
 
var
        SalesLine: Record "Sales Line";
        Item: Record Item;
        SalesLineType: Enum "Sales Line Type";
        SalesDocumentType: Enum "Sales Document Type";
        ItemType: Enum "Item Type";
        ShowMandatoryValue: Boolean;
I have the same question (0)
  • Suggested answer
    RockwithNav Profile Picture
    8,419 Super User 2025 Season 2 on at
    Sales Order Subform Conditional ShowMandatory
    The only thing you need to make sure is - Is this getting triggered at the right time?
    Did you try with page triggers - OnAfterGetCurrRecord?

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,351

#2
Sumit Singh Profile Picture

Sumit Singh 2,072

#3
YUN ZHU Profile Picture

YUN ZHU 1,807 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans