Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Onload client script button not working

krishnanara
Tera Contributor

Hi,

In the below onload client script, I kept the button "clear flag" when we click on this button it should make the checkbox field  u_cirt_in_progress to false and should save the form and stay on the same page but right now it is taking me to the new record page after clicking and it is not setting the checkbox field  u_cirt_in_progress to false. Could you please provide the fix for this?

 
function onLoad() {

    if (g_form.getValue('u_cirt_in_progress') == 'true') {

         g_form.addErrorMessage(
            '⚠ This account in progress ' +
            '<button onclick="clearflag()">Clear Flag</button>'
        );

    }
}

function clearflag() {
g_form.setValue('u_cirt_in_progress, 'false');
g_form.save();
    return false;
}
11 REPLIES 11

Tanushree Maiti
Tera Patron

Hi @krishnanara 

 

The issue occurs because of a syntax error in your g_form.setValue line in your clearflag(). 

 

function clearflag() {
g_form.setValue('u_cirt_in_progress', 'false');
g_form.save();
    return false;
}
 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

I tried but still didn't work. it is still taking me to the new record page