Populate error message in OnLoad client script with Script include

Surendra6
Tera Contributor

Hello,

We got a requirement of one field ABC is refence to another table and if it is taking inactive records then showing alert or error message if form loads. Please let us know how can we achieve in onLoad client script.

 

Thank you!!

6 REPLIES 6

Sagar Pagar
Tera Patron

Hi,

 

Try this in Client script. Note- Modify it as per your field names.

    var abc_field_value = g_form.getReference("abc", checkActive);

    function checkActive(abc_field_value) {

     //   alert(abc_field_value.active);

        if (abc_field_value.active == "false") {
            alert("The " + abc_field_value.name + " is in-active.");

            g_form.addErrorMessage("The " + abc_field_value.name + " is in-active."");
        }
    }

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Hi Sagar,

I have tried your client script but it is not working, not showing the alert or error message after form load. Please check from your end.

Thanks!!

Hi,

 

I have added it for Change request [rfc] field on incident form. It is working as expected for me & showing alert/ Error message when the Change request state is closed.

 

Share you client script configurations and your form screenshots. It will help to troubleshoot the issue.

 

Thanks!

Sagar Pagar

The world works with ServiceNow

Hey, 

I think name of the function is incorrect:

function checkChangeState(abc_field_value) {

 

It should be:

function checkActive(abc_field_value) {
Best Regards
Aman Kumar