Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

use case

girilokesh9
Tera Contributor

On form two dates field , if data1 is not equal to date2 the string field should populate.

2 REPLIES 2

Satishkumar B
Giga Sage
Giga Sage

Hi @girilokesh9 

Client Script

  1. Create Client Script:
    • Type: onChange

Field: date1 (and create another for date2 )

 

 

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

    var date1 = g_form.getValue('date1'); // Replace with your first date field name
    var date2 = g_form.getValue('date2'); // Replace with your second date field name

    if (date1 !== date2) {
        g_form.setValue('string_field', 'Dates are not equal'); // Replace with your string field name
    } else {
        g_form.setValue('string_field', ''); // Clear the string field if dates are equal
    }
}
​

 

 

Replace 'date1', 'date2', and 'string_field' with the actual field names in your form.

-----------------------------------------------------------------------------------

Please consider marking my reply as Helpful 👍 and/or Accept Solution ✔️, if applicable. Thanks!

 

Community Alums
Not applicable

Hi @girilokesh9 ,

 

To achieve the requirement you need to create a 2 client script to check both the dates and then update the string field with your required text.

The onChange client script should look like the below- Put on Date1 Field, create another for Date2

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    var date1 = g_form.getValue('date1Field');
    var date2 = g_form.getValue('date2Field');
    if (date1 !== date2) {
        g_form.setValue('stringField', 'YOUR TEXT');
    }
}

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar