Need to be able to abort UI action submit if Configuration Item is blank, but still allow to save.

ksmithdev
Mega Expert

In the Request Approval button, when clicked, I need it to error in the CI field and not allow to submit. But, if someone clicks Save, to allow the CI to remain blank and continue onwards. I have changed the script for the UI action, but it isn't working no matter which way I try. It is allowing submittance of a blank CI and for save. It seemed an abort client script running with the button seemed to work, but it didn't allow it to be saved. Here is what I have so far:

 

Condition: current.approval=='not requested' && gs.hasRole("itil")

 

 

reqCloseNotes();

function reqCloseNotes(){

  g_form.hideFieldMsg('cmdb_ci', true);

    if(g_form.getValue('cmdb_ci') == ''){

          //Remove any existing field message, set mandatory, and show a new field message

          g_form.hideFieldMsg('cmdb_ci');  

          g_form.showFieldMsg('cmdb_ci','Configuration Item is a mandatory field. Please choose a valid configuration item before submitting.','error');

          return false;

    } else {  

        gsftSubmit(null, g_form.getFormElement(), 'pcg.request.approval');

  }

}

 

if(typeof window == 'undefined')

  closeComplete();

 

function closeComplete(){

  action.setRedirectURL(current);

  current.approval='requested';

  current.update();    

}

1 ACCEPTED SOLUTION

I got it. What was wrong was the order that you sent me originally, it was doing current.update after the redirect, and also I had to change the UI action to call itself in the Onclick rather than within the script. After changing those two things, it started to work. Thank you though, as a developer its always nice to have a second pair of eyes here and I couldn't have gotten it without you.



function reqCloseNotes(){  


    if(g_form.getValue('cmdb_ci') == ''){  


          //Remove any existing field message, set mandatory, and show a new field message      


          g_form.showFieldMsg('cmdb_ci','Configuration Item is a mandatory field. Please choose a valid configuration item before submitting.','error');  


      gs.log("sys ID of UI action : " + current.sys_id);


          return false;


    }


        gsftSubmit(null, g_form.getFormElement(), 'pcg.request.approval');


 


}  


 


if(typeof window == 'undefined')  


  closeComplete();  


 


function closeComplete(){  


  current.approval = 'requested';


    current.update();


    action.setRedirectURL(current);


}  


View solution in original post

7 REPLIES 7

You could, but that doesn't account for situations when the value of the CI field changes while the form is displayed.   The conditions that control the display of the button are only evaluated as the form are being rendered so you still have to evaluate the conditions on submit and abort if they are not met.   That requires a client script...which is being invoked in the UI action in this case.


I got it. What was wrong was the order that you sent me originally, it was doing current.update after the redirect, and also I had to change the UI action to call itself in the Onclick rather than within the script. After changing those two things, it started to work. Thank you though, as a developer its always nice to have a second pair of eyes here and I couldn't have gotten it without you.



function reqCloseNotes(){  


    if(g_form.getValue('cmdb_ci') == ''){  


          //Remove any existing field message, set mandatory, and show a new field message      


          g_form.showFieldMsg('cmdb_ci','Configuration Item is a mandatory field. Please choose a valid configuration item before submitting.','error');  


      gs.log("sys ID of UI action : " + current.sys_id);


          return false;


    }


        gsftSubmit(null, g_form.getFormElement(), 'pcg.request.approval');


 


}  


 


if(typeof window == 'undefined')  


  closeComplete();  


 


function closeComplete(){  


  current.approval = 'requested';


    current.update();


    action.setRedirectURL(current);


}  


ksmithdev
Mega Expert

Also, I put an "else" submit. Woops.