Client Script for Timestamping "checks" field.

Wayne Miller
Tera Guru

We have a solution in App Engine for our onboarding team to process cases, on which we have a set of "checks" fields, mostly checkboxes:

WayneMiller_0-1751879330614.png

We have a current mechanism in "flow" to trigger when an Agent marks a check as complete to time/date stamp and add their name.

 

While this works "okay", I've found that flow triggers can be a bit "hit-and-miss", insofar, as sometimes the timestamps don't populate after a save.

 

I would like to make this a little more robust with an "on-change" Client Script to auto-populate the date/time and Agent name.

 

Is this possible? 

 

I'm not the greatest in Javascript, so any suggestions would be very much appreciated.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Wayne Miller 

you can use onChange client script on each of those checkboxes

Sample script for 1 is like this, please enhance

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == '')
        g_form.clearValue('yourField');

    if (newValue.toString() == 'true') {
        var today_date = new Date();
        var today_date_time_str = formatDate(today_date, g_user_date_time_format);
        var name = g_user.firstName + ' ' + g_user.lastName;
        g_form.setValue('yourField', today_date_time_str + " " + name);
    }

}

Another alternative is to use before update business rule and check which checkbox got checked and only update that field

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Wayne Miller 

you can use onChange client script on each of those checkboxes

Sample script for 1 is like this, please enhance

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == '')
        g_form.clearValue('yourField');

    if (newValue.toString() == 'true') {
        var today_date = new Date();
        var today_date_time_str = formatDate(today_date, g_user_date_time_format);
        var name = g_user.firstName + ' ' + g_user.lastName;
        g_form.setValue('yourField', today_date_time_str + " " + name);
    }

}

Another alternative is to use before update business rule and check which checkbox got checked and only update that field

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Wayne Miller
Tera Guru

Wonderful!  Works perfectly.  Thanks, as always, Ankur!

@Wayne Miller 

Glad to help.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader