Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Show message when you click in the button

mustapharabat
Mega Expert

Hi all

In a UI Action "Resolve Incident", I would like that when clicking on the "Resolve incident" button, I would like the message below to appear if the mandatory fields are not filled:

find_real_file.png

Here is the script of the UI Action "Resolve Incident":

find_real_file.png

 

function resolveIncident(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
if (!jQuery('.is-required').length){

alert("Veuillez remplir les champs obligatoires");

}
else
{g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
//if (g_form.getValue('comments') == '') {
//Remove any existing field message, set comments mandatory, and show a new field message
//try {g_form.hideFieldMsg('comments');} catch(e) {}
//g_form.setMandatory('comments', true);
//g_form.showFieldMsg('comments','Comments are required when resolving an Incident','error');
//return false; //Abort submission
//}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}


}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();

function serverResolve(){
gs.log("A Test save");
current.incident_state = 6;
current.state = 6;
current.update();
}

 

Thanks for your help
 
1 ACCEPTED SOLUTION

Ct111
Tera Sage

Hi , 

 

You can use code  like below 

 

 

if(current.state == 6)

{

var notes = g_form.getValue('close_notes');     // put the correct field name in getValue

var code  = g_form.getValue('close_codes');

if(notes.length != 0  ||  code.length != 0)

{

g_form.addErrorMessage('The close notes and close codes are mandatory while resolving incident');

 

return false;

}

 

 

}

View solution in original post

8 REPLIES 8

Ct111
Tera Sage

Hi , 

 

You can use code  like below 

 

 

if(current.state == 6)

{

var notes = g_form.getValue('close_notes');     // put the correct field name in getValue

var code  = g_form.getValue('close_codes');

if(notes.length != 0  ||  code.length != 0)

{

g_form.addErrorMessage('The close notes and close codes are mandatory while resolving incident');

 

return false;

}

 

 

}

Hi

 

Thank you so much for your reply

But when I apply this script, When I click on the button "resolve incident" the field "Incident state" takes the value 6.

I would like this field to keep its initial value and not to take the value 6





Thank you for your help

Best regards

Here is the script:

 

 

find_real_file.png

function resolveIncident(){

var notes = g_form.getValue('close_notes'); // put the correct field name in getValue


var code = g_form.getValue('close_codes');
var Istate= g_form.getValue('incident_state');
var state= g_form.getValue('state');

if(notes.length != 0 || code.length != 0)


{


g_form.addErrorMessage('The close notes and close codes are mandatory while resolving incident');
g_form.setValue('incident_state', Istate);
g_form.setValue('state', state);
return false;


}


else {
{g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}
}

}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
serverResolve();

function serverResolve(){
gs.log("A Test save");
current.incident_state = 6;
current.state = 6;
current.update();
}

mustapharabat
Mega Expert

Hi

 

Thank you so much for your reply

But when I apply this script, When I click on the button "resolve incident" the field "Incident state" takes the value 6.

I would like this field to keep its initial value and not to take the value 6





Thank you for your help

Best regards