UI Builder Form Component Validation Messages

Velma
Tera Guru

How can I get the validation messages (e.g., required field not filled in) to show? Also, can I access an event to allow me to show a Save succeeded or Save failed message? I don't see what event to use on the form component or the glide form data resource. (A pointer to a really good video or tutorial on the form component details would be most welcome.)

6 REPLIES 6

Yousaf
Giga Sage

Hi Velma,

Check these links if thats what you looking for 

UI Builder Form Validation - Youtube

UI Builder Client Script

 

Mark Correct or Helpful if it helps.

Thanks,
Yousaf


***Mark Correct or Helpful if it helps.***

Thanks, @Yousaf. That video is about validation and hand-jammed forms. (I do remember watching it some time ago, and I have built some hand-jammed forms.) This question though is about using the form component and glide form--that is standard ServiceNow forms--which is entirely separate from that. (Client scripts could be relevant if there are events I could capture to generate the messages myself--but I am unable to find those events.)

JagjeetSingh
Kilo Sage
Kilo Sage

Hi,

Is this your custom page?

There are many ways to show your message.

1. From event.

On event trigger you can use "Add Alert Notifications" event. It is a page level event handler.

It accepts data in JSON format. Example below:

[{"type":"info","message":"Successfully saved the record."}]

2. From page script.

If you are triggering the event and want to show the notification after validating or executing some other logic then you can show your alert from page script as well. Example below.

api.emit("NOW_UXF_PAGE#ADD_NOTIFICATIONS", {
                items: [{
                    id: "alert1",
                    status: "critical",
                    icon: "info-circle-outline",
                    content: {
                        type: "string",
                        value: "Failed to update."
                    },
                    action: {
                        type: "dismiss"
                    },
                }]
            });

here api.emit is used to emit any page level notification. "NOW_UXF_PAGE#ADD_NOTIFICATIONS" is the event name which is used in point 1. Only thing you need to change here is Status, icon if needed and the content.

 

Mark correct/helpful if it works for you. 🙂

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

Thank you, @Jagjeet Singh. That is a fine documentation for how to display messages--I'll keep it for a reference. I've used a couple of methods but not the second one you document and I always like knowing how to do something in a script. However--my post must not be clear--how to display is not my problem. There are no related events that I can find. The automatic messages that glideform shows for required fields are not showing although that internal validation is running (the not filled in required fields are highlighted by a not very visible border outline and the form does not save). While the onLoad and onChange client scripts are working great as well as UI Policies, the onSubmit client script is not hitting, so I cannot build validation in a script. There is no submit or validation event. The data resource does not have a Save successful or Save failed event. (Note: These are forms that work perfectly in both Platform and Service Portal.) I'm still hoping there is a configuration I am missing and someone will tell me and it will become useable. 🙂