make comments mandatory when UI action is clieked

RudhraKAM
Tera Guru

Hello 

I have a UI action when clicked it will change The incident state to assigned and additional comments are mandatory 

I am trying to use this below script but having some trouble to show up the UI action if the client is checked so I removed the client check box in the UI action and now its showing in portal . If i click on the UI action can we show alert message and make additional comments mandatory ? and also is there any other way we can show the UI actions in portal without un-checking the client in UI action.

// Client side onclick function
function reopenIncident() {
    g_form.hideFieldMsg('comments');
    var usrResponse = confirm('Are you sure you want to reopen the resolved incident? If yes, please add Additional Comments to continue.');
    if (usrResponse == true) {
        g_form.setValue('incident_state', 2);
        g_form.setValue('state', 2);

        if (g_form.getValue('comments') == '') {
            g_form.setMandatory('comments', true);
            g_form.showFieldMsg('comments', getMessage('You must add a reason in Additional comments in order to reopen an incident'), 'error');
            return false; //Abort submission
        }
        // Call the UI Action and skip the 'onclick' function
        gsftSubmit(null, g_form.getFormElement(), 'reopen_incident'); // MUST call the 'Action name' set in this UI Action
    } else {
        return false;
    }
}

if (typeof window == 'undefined')
    serverReopen();

function serverReopen() {
    
    current.incident_state = 2;
    current.state = 2;
    current.close_code = "";
    current.close_notes = "";
    current.update();
    action.setRedirectURL(current);
}
1 ACCEPTED SOLUTION

If you want to show on portal form then you have to set client as false And now here you will do the validation in server side code. Eg: if you want to some error message based on comment field then you can validate inside if else block If ( current.comments ==“”) { gs.addErrorMessage(“test”); } else{ current.=‘ ’; current.update(); }

View solution in original post

5 REPLIES 5

Shantharao
Kilo Sage

Hi,

you can create simple client script as like below

if (g_form.getActionName() == "back_end_ui_action_name") {  find_real_file.png

g_form.setMandatory('comments', true);

g_form.addInfoMessage("please fill the comments");

return false; //Abort submission

}

 

Please mark the answer if it resolves you query or please hit the help button if it helps you