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

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

Since you have unchecked the Client-Callable checkbox it will not be called Client side & function reopenIncident() is of no use then.

Also, alert can be produced only on client side part. In addition, if you will you can use gs.addErrorMessage() in your code & abort the action in case comments are not filled & provide an Error message stating 'Comments mandatory'.

is there any other way to show the UI actions on portal ?

 

For portal always recommended to go with Widget approach. If you are looking for step-by-step option then you can refer link for a check.

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(); }