Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set the valude after clear the variables

nikhitha24
Tera Guru

Hi All,

 

I have written on change catalog client script to clear the value on the variable.

 

Example:

Before clear the value i have default values need to set for the variable.

nikhitha24_0-1707122031355.png

 

I have written the catalog client script:

 

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

        g_form.clearValue('request_number');
        g_form.clearValue('what_action_do_you_require');
        g_form.clearValue('change_record_number');
        g_form.clearValue('email_updates_and_final_report');
        g_form.clearValue('schedule_date_time_for_snapshot_creation');
        g_form.clearValue('schedule');
        g_form.clearValue('snapshot_retention_period');
        g_form.clearValue('catalog_item');
        g_form.clearValue('snapshot_change');
        g_form.clearValue('affected_ci');
    }
    else if(oldValue == "me") {
        g_form.clearValue('request_number');
        g_form.clearValue('what_action_do_you_require');
        g_form.clearValue('change_record_number');
        g_form.clearValue('email_updates_and_final_report');
        g_form.clearValue('schedule_date_time_for_snapshot_creation');
        g_form.clearValue('schedule');
        g_form.clearValue('snapshot_retention_period');
        g_form.clearValue('catalog_item');
        g_form.clearValue('snapshot_change');
        g_form.clearValue('affected_ci');
    }
}
 
After clear the values how can set the default values again.
 
nikhitha24_1-1707124236299.png

 Please help me on this requirment

 

2 REPLIES 2

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @nikhitha24 

 

As per my lil knowledge, once a field value is clear it means the default value also get clear and now system will not use ootb default value. So you need to write script

 

https://www.servicenow.com/community/developer-forum/how-to-set-initial-default-value-from-client-sc...

 

May i know what is your exact use case

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Harish KM
Kilo Patron
Kilo Patron

Hi @nikhitha24 you can set the default value inside the below function

if (newValue == '') {
g_form.setValue('fieldname','value'); // this value will be set when newValue is empty.
}

Regards
Harish