Set field to be mandatory on Card Page

Hey All, 

Working with NAV 16

I've got a page action on a card page that creates a new customer record, essentially. It's called 'Create Client'

My goal is to make a certain field on this page, 'Client Code' mandatory. 

I don't need the field to be mandatory ALL the time, only when they call the creation process from this page action. 

I tried to set field properties to accomplish my task:

ShowMandatory for Client Code = TRUE

But this doesn't actually enforce that the user enter this code before closing the card page. 

NotBlank for Client Code = YES 

This didn't work because it only prevents the user from closing the page with a blank client code IF it originally was filled in. In my situation now I need it to be enforced, where if a record will be saved from the action then a 'Client Code' must be entered.

Are there any properties that I missed?  

The code for the page action: 

Create Client - OnAction()
// create a new Client

<Action106> - OnAction()

<Action107> - OnAction()

<Action108> - OnAction()

New Work Order - OnAction()
IF VAR_CreditHold THEN
ERROR('Customer has credit hold. Cannot create work order.');

// exit is customer is inactive
IF (Inactive) THEN

IF (VAR_CustomerRec.GET("No.")) THEN

  • On the OnQueryClosepage trigger you can add a code to check if the field Client code is filled in.
  • In reply to sbhatbng:

    Found the OnQueryClosePage trigger.

    Should I perform the check using TESTFIELD?
  • In reply to Rob :

    You can use TESTFIELD or you can give your own error message using Error function.
  • In reply to Rob :

    used this on the trigger.

    IF Client_code = ''
    ERROR('Please insert a value into the Client code field');

    thanks !
  • In reply to Rob :

    Yes, this will work, when user tries to close the page and if Client code is blank then user will get this message.
  • In reply to Rob :

    1  I would perform this check in table-trigger OnModify. Recommended to do it via Events.

    2  Property NotBlank does only work on fields that are part of primary-key.

    3  Property ShowMandatory only informs the user, that the field should contain some value. It does not demand anything.

    Otherwise: More correct syntax is using FIELDCAPTION:
    ERROR('Please insert a value into the field "%1".', FIELDCAPTION("Client Code"));

    And to be perfect, use Textconstants  ;)