UI action script bypass the mandatory field

eliana_wise
Tera Contributor

Hi,

I have a UI action script for Reject which is asking if the user clicked on Reject confirm if they want to proceed and then another pop up to ask them to fill out work notes for reject reason, but whenever I click reject I see confirm, pop up and the page reloads with out letting me to fill in work notes. Please advise.

function rejectTicket(){

var answer=confirm("Are you sure you want to reject this change?");

if(answer == false){

return false;

}

else {

gsftSubmit(null, g_form.getFormElement(), 'i_heart_rejecting');

alert('Please fill out the reject reason in notes section');

g_form.setMandatory('work_notes', true);

reject();}

}

if(typeof window == 'undefined')

runCode();

function runCode(){

appRec.state = 'rejected';

current.field =

gs.addInfoMessage('Change '+ current.number + ' has been rejected');

}

function reject(){

  var myApp = new ChangeApprovalUtils().checkMyApprovals(current.sys_id);

  var appRec = new GlideRecord('sysapproval_approver');

  appRec.addQuery('sys_id',myApp);

  appRec.query();

  if (appRec.next()){

appRec.state = 'rejected';

appRec.update();}

}

1 ACCEPTED SOLUTION

Sagar V1
Mega Expert

Hi Eliana,



Set the field 'work_notes' mandatory before gsftSubmit as shown below,




if(answer == false){


return false;


}




else {


if(g_form.getValue('work_notes')=='')


{


g_form.setMandatory('work_notes',true);


alert(getMessage('rejectpopup'));


return false;


}


else


{


gsftSubmit(null, g_form.getFormElement(), 'i_heart_rejecting');


alert('Please fill out the reject reason in notes section');




reject();


}


}



PS - Please mark Helpful, Like, or Correct Answer if applicable.


Regards,


Sagar


View solution in original post

5 REPLIES 5

lakshminarayan4
ServiceNow Employee
ServiceNow Employee

Hi ,


redirection part is missed in the code. In the reject method , you need to put this line of code



action.setRedirectURL(current);



Tha ks


Hi Eliana



Use the below line after the g_form.setMandatory line


gsftSubmit(null, g_form.getFormElement(), 'i_heart_rejecting');




There is some other issue which I am seeing on your script


1. You are using appRec object in runcode function, but this object is neither global nor defined in the function.


Sagar V1
Mega Expert

Hi Eliana,



Set the field 'work_notes' mandatory before gsftSubmit as shown below,




if(answer == false){


return false;


}




else {


if(g_form.getValue('work_notes')=='')


{


g_form.setMandatory('work_notes',true);


alert(getMessage('rejectpopup'));


return false;


}


else


{


gsftSubmit(null, g_form.getFormElement(), 'i_heart_rejecting');


alert('Please fill out the reject reason in notes section');




reject();


}


}



PS - Please mark Helpful, Like, or Correct Answer if applicable.


Regards,


Sagar