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

Notifications

Announcements

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 980

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)
  • Indira88 Profile Picture
    980 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

  • Suggested answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 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
    980 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?

  • Verified answer
    Suresh Kulla Profile Picture
    50,251 Super User 2025 Season 2 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.

  • Suggested answer
    JAngle Profile Picture
    137 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

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

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,457

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 742 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 669 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans