How to abort the action performed by the user for onChange client script

Ulka1
Tera Contributor

Hi,

 

I need to abort an action performed by the user by using onChnage client script. 

Please could anyone help me to get it done.

18 REPLIES 18

Ankur, i tired this solution but it is not working for error message display.

should show the error message irrespective of whether it's global or scoped app

Regards
Ankur

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

if that doesn't work then you can use onSubmit with GlideAjax

But you need to have workaround so that Ajax waits for the script include function

Regards
Ankur

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

shloke04
Kilo Patron

Hi @Ulka 

If you want to do it using an On Change Client Script then you need to clear that field and make that field as Mandatory and that will make sure the user is not able to submit the form and will solve your purpose as well.

Sample script shared below where I am clearing out the field and making it mandatory as well:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
	if(newValue){
		//Add your condition which you want to check
		g_form.clearValue('Field Name'); // Replace "Field Name" with your Field here
		g_form.setMandatory('Field Name',true); // Replace "Field Name" with your Field here
	}

   //Type appropriate comment here, and begin script below
   
}

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Ulka1
Tera Contributor

Hi Shloke,

Thank you for the response.

But scenario is when the HR case is created and assign to 'Assign to user', then the assign to user should not close the case by clicking on the 'Resolve Case' button until and unless the related HR tasts gets closed complete. So here as per requirement, expected  is to display the error message that "HR tasks are not closed complete, first complete it". and at the same time the action performed by the assign to user (clicked on "Resolve Case" UI action) gets aborted.

 

I am able to display the error message by using onChange client script and script include, but the action is not getting aborted.(Once the assign to user clicks on Resolve Case UI action, case state is getting change to Resolved" even the HR tasks are not completed. Which should not get happened. 

Could you please suggest me to achieve this requirement.