Client script - on change

Lidi2115
Tera Contributor

Hi to everyone.

I'm trying to create a script client that emits an alert when the availability field record changes to reserved.

Can someone help me?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var dis = g_form.getValue("availability");
    if (newValue == "reserved") {
        alert("Reserved room");
    }

}
1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Lidi2115,

onChange() script is executed when the end-user opens the form or when the form is opened. It won't execute after the form is closed. That is, if the form is closed and flow designer changes the field, onChange() script won't execute.

If there is a need to get notified when a value is changed in Flow Designer, use notification to send email or send a message.

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/notification/reference...

There is a "Send Notification" step in Flow Designer.

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/flow-designer/referenc...

View solution in original post

12 REPLIES 12

Hi Sachin,

I tried here, but it didn't work either.

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Lidi2115,

onChange() script is executed when the end-user opens the form or when the form is opened. It won't execute after the form is closed. That is, if the form is closed and flow designer changes the field, onChange() script won't execute.

If there is a need to get notified when a value is changed in Flow Designer, use notification to send email or send a message.

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/notification/reference...

There is a "Send Notification" step in Flow Designer.

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/administer/flow-designer/referenc...

Hi Hitoshi,

I need an alert (pop up) to appear on the user's screen when the form is closed and the flow designer changes the field to reserved.

That way the user would validate that the record was successfully added immediately and not by email.

Can I do it with the onSubmit() script? If yes, how?

@Lidi2115 Following onSubmit() will check if the availability changes to "reserved" and display an alert.

function onSubmit() {
    if (g_form.getValue("availability") == "reserved") {
        alert("Reserved room");
    }
}

>I need an alert (pop up) to appear on the user's screen when the form is closed and the flow designer changes the field to reserved.

My bad. Above script will only work when the end-user changes the field. It won't work when flow designer changes the field.

Showing alert on client's form page is not possible because Flow Designer executes on the server and not on the client pc.

The only alternative is to have Flow Designer send a notification. Notification can be a SMS and not an email notification. SMS notification will show up as an alert when the user is logged in.

https://docs.servicenow.com/en-US/bundle/sandiego-servicenow-platform/page/administer/notification/c...