How to disable the submit button in the catalog form if the variable choice option is Disagree

Sanjay E
Kilo Contributor

How to disable the submit button in the catalog form if the variable choice option is selected as Disagree

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sanjay E 

Why not use onSubmit catalog client script and if the variable is Disagree stop form submission

function onSubmit(){

	if(g_form.getValue('variable') == 'Disagree'){
		alert('Not allowed');
		return false;
	}

}

you need to write onChange catalog client script on that variable

Show/hide the button using DOM

Note: DOM is not recommended approach

check this link for help

Show/Hide Submit button on Catalog Item

Regards
Ankur

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

View solution in original post

15 REPLIES 15

function onSubmit() {
    //Type appropriate comment here, and begin script below


    if (g_form.getValue('field_name') == 'disagree') {
       // alert("Please enter values");
        return false;
    } else
{
return true;
}
}

try this script and modify accordingly

Thanks,

Murthy

Thanks,
Murthy

Hi 

And one more doubt 

If you don't want to submit the form when user selects disagree why dont you remove it from the choices?

 

Thanks

Thanks,
Murthy

Baala T
Mega Guru

Hi Sanjay,

Please do check this link for both OnSubmit and OnChange option

https://community.servicenow.com/community?id=community_question&sys_id=47171141db2997402328f3231f9619aa

 

Regards,
Bala T

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Sanjay E 

Why not use onSubmit catalog client script and if the variable is Disagree stop form submission

function onSubmit(){

	if(g_form.getValue('variable') == 'Disagree'){
		alert('Not allowed');
		return false;
	}

}

you need to write onChange catalog client script on that variable

Show/hide the button using DOM

Note: DOM is not recommended approach

check this link for help

Show/Hide Submit button on Catalog Item

Regards
Ankur

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

Hello @Ankur Bawiskar 

 

I have a similar requirement and I have done that but somehow the catalog item gets submitted.
Script include:

ElenaPomana_0-1676471147533.png

Client script:

ElenaPomana_2-1676471237928.png

 

Thank you,

Elena