User criteria Script

Souvik
Tera Contributor

Hi Team ,

 How can we show error message when user criteria returns false?

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Souvik Since user criteria is a server side script, you can use gs.addErrorMessage() or gs.addInfoMessage() to show error or info message to your user.

 

    gs.addInfoMessage('start must be before end');

 

Hope this helps.

Rajesh Chopade1
Mega Sage

Hi @Souvik 

To show an error message when a user criteria returns false, you typically need to handle this in a place where user actions or data validations occur. This can be done using a few different methods, such as within a Business Rule, Client Script, or UI Policy.

 

Business rule

(function executeRule(current, previous /*null when async*/) {
    // Define your user criteria logic here
    if (/* user criteria returns false */) {
        gs.addErrorMessage('Your custom error message here.');
        current.setAbortAction(true); // Prevents the record from being saved
    }
})(current, previous);

 

Client script

function onSubmit() {
    // Define your user criteria logic here
    if (/* user criteria returns false */) {
        g_form.addErrorMessage('Your custom error message here.');
        return false; // Prevents form submission
    }
    return true; // Allows form submission
}

 

UI Action

function onClick() {
    // Define your user criteria logic here
    if (/* user criteria returns false */) {
        gs.addErrorMessage('Your custom error message here.');
        // Optionally: Redirect or abort action
        return false; // Prevents further action
    }
    // Continue with UI action logic
}

 

I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.

thank you

rajesh

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

How do you envision this working?

If the user criteria returns false the user will not see the object itself. So where and how do you want to show the message?

Also, There will be a lot of catalogs/articles user cannot see, How and Why would you show message that article X exists but you cant see it for ABC reason. It will create more confusion?

-Anurag