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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Making an option Field mandatory and not letting user create a job Planning line

(0) ShareShare
ReportReport
Posted on by 990

Hi ,

I have a field that I need to set to mandatory and stop the line to be created when the field is blank.

I tried to do this as a test field on Insert trigger in the page  ,even after entering the data in the field I get an alert "This field cannot be validated since the key fields are not valid."

Any idea how this could be achieved?

pastedimage1615213402708v2.png

I have the same question (0)
  • Suggested answer
    JAngle Profile Picture
    150 on at

    You tried doing the check at table level instead? Use a codeunit and create an event subscriber to the job task table OnAfterInsert. You will need to verify if some other fields are populated before doing your check. Need at least Job No. and Job Task No. so that the primary key is set and you have correct data context.

    Another option might be to check if data is blank OnClosePage trigger for the job card

  • Verified answer
    Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 on at

    Can you share the code you have written? and which field you want to make the field mandatory, the highlighted field Posting Gropu is not an option field.

    As Josh mentioned the best place for you to add is by subscribing to the  OnInsertTrigger of table or you could add in OnValidate of another field that way you can check if your field is populated before they select a value in that.

  • Indira88 Profile Picture
    990 on at

    Sharing My Code:

    Table.Ext

     trigger OnBeforeInsert()

       begin

           if JPLMgmt.AssignObjectId() = 'Page Job Planning Lines' then begin

               if Rec."WCI Job Posting Group" = '' then begin

                   Rec.TestField(Rec."WCI Job Posting Group");

               end;

           end;

       end;

    Page.Ext Code:

    trigger OnAfterGetCurrRecord()

        begin

            ObjectId := (CurrPage.ObjectId(true));
            if ObjectId = 'Page Job Planning Lines' then begin
                JPLMgmt.SetObjectId(ObjectId);
            end;
        end;
     trigger OnClosePage()
        begin
            ObjectId := '';

            JPLMgmt.SetObjectId(ObjectId);


        end;

    CodeUnit Code:

     procedure SetObjectId(var ObjectId: Text): Text

       begin

           if ObjectId = 'Page Job Planning Lines' then begin

               ObjectIdP := ObjectId;

           end

           else begin

               ObjectId := '';

               ObjectIdP := ObjectId;

           end;

           exit(ObjectIdP);

       end;

       procedure AssignObjectId(): Text

       begin

           ObjectIdP := ObjectIdP;

           exit(ObjectIdP);

       end;

    The issue with this is when editing in excel the job Group is not considered mandatory, the user can save values without entering the Job Posting Group.

    trigger OnValidate cannot be used for existing fields.

    Does OnAfterValidate work?

  • Suggested answer
    Suresh Kulla Profile Picture
    50,269 Super User 2026 Season 1 on at

    Firstly, how your assignment of the page object will reflect on the table when you retrieve, I am not quite what you are trying to do with that code, if you just a add simple statement

    Rec.TestField(Rec."WCI Job Posting Group"); by subscribing to the existing event of the table.  You don't need a table ext for that.

  • Indira88 Profile Picture
    990 on at

    Hi Kulla,

    In business central there are in my knowledge two flows where the data gets inserted in the job Planning Lines.

    for the normal case through the Job Planning Line via New Line and through Job Ledger -> Transfer to job Planning Lines.

    if I keep the code without the codeunit then in all cases it gives the alert.

    Also I tried doing the simple onInsert Trigger Page Level,

    It was giving me that validation alert in the subject of the thread.

    Regards,

    Indira

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,821 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,122 Super User 2026 Season 1

#3
Dhiren Nagar Profile Picture

Dhiren Nagar 959 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans