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

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

Service_RNow
Mega Sage

HI,

PLease try below code :=

function resolveIncident(){
//Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
g_form.setValue('incident_state', 6);
g_form.setValue('state', 6);
g_form.setValue('resolved_by', g_user.userID);

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(){
current.incident_state = IncidentState.RESOLVED;
current.state = IncidentState.RESOLVED;
current.resolved_by = gs.getUserID();
current.update();
}

Please mark reply as Helpful/Correct, if applicable. Thanks!

 

Thank you for your reply

find_real_file.png

 

For example on this incident, the "incident state" is on "awaiting problem".
But when I click on "resolve incident" the field takes the value 6.

 

find_real_file.png

I would like it to remain on its initial state (for example here it is "awaiting problem") and displays the warning message: "The following mandatory fields are not filled in: Close code, Close notes"

 

Thanks

mustapharabat
Mega Expert

Thank you for your reply

find_real_file.png

 

For example on this incident, the "incident state" is on "awaiting problem".
But when I click on "resolve incident" the field takes the value 6.

 

find_real_file.png

I would like it to remain on its initial state (for example here it is "awaiting problem") and displays the warning message: "The following mandatory fields are not filled in: Close code, Close notes"

 

Thanks