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

Mark Stanger
Giga Sage

I've tried answering your question in the other thread.   You need to set this up in a demo instance where I can take a look at it and troubleshoot.


Due to the customization in the instance I am writing this in, it isn't working. I found out it was spamming due to a business rule running the same thing. But after deleting it, nothing is working as a UI action. It doesn't work in a demo instance either, if you drop it.


You needed to have the 'Client' checkbox checked and your function call in the 'onClick' field so that some action would take place when the button was clicked.



Please mark this answer as correct if I've answered your question.


ghaynie
Kilo Explorer

Can you just have two buttons?   One that appears if the CI is blank, and one that appears if it is not blank?   The first one button would simply save it, and the second button would submit it.