How to make comments mandatory when user click on Approve And reject button

suresh40
Tera Contributor

Hi All,

 

I have requirement how to make comments mandatory when user click on Approve And reject button 

Approve script

current.update();
var currentRec = current.sys_id;
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval',currentRec);
gr.addQuery('state', 'requested');
gr.query();
 
while (gr.next()) {
   gr.state = 'approved';
   gr.update();
 
}
3 REPLIES 3

Mohith Devatte
Tera Sage
Tera Sage

Hello @suresh40 ,

You wrote this script in a BR or a UI action ?

 

Hi Mohith ,

 

I have written UI Action .

@suresh40 you can modify the script to below 

 

var currentRec = current.sys_id;
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval',currentRec);
gr.addQuery('state', 'requested');
gr.query();
 
while (gr.next()) {
if(!current.comments.isNil())
{
   gr.state = 'approved';
   gr.update();
}
else{
gs.addErrormessage("Comments are mandatory");
current.setAbortAction(true);
}
 
}

 

OR

 

what you can do is you can enable this Ui action on client side too by checking client check box and write one client code in the on click function to set the comments field mandatory and then use gfst submit to run the server code 

 

some thing like this 

function executeClient(){
 if(g_form.getValue('comments')=="")
{
   g_form.setMandatory('comments', true);
   gsftSubmit(null, g_form.getFormElement(), 'approve');  // replace approve with yor button action name
}
}

if(typeof window == 'undefined'){
   executeServer();
}

function executeServer(){
//your server side script
}

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks