Cancel comment mandatory on Service Portal

Ankita Gupte
Kilo Sage

Hello Experts,

 

I have requirement to make cancel comments mandatory on click of UI Action which is visible on Service Portal only for Self-service and Service Portal view.

 

So when cancel UI action is clicked the additional comments must become mandatory and on filling that then incident should get cancel.

Below is the code. Please advice how can we achieve it.

 

AnkitaGupte_0-1694681627439.png

function cancelIncident() {
    //Set the 'Incident state' and 'State' values to 'new/assign/inprogress/onhold', and display mandatory fields
   g_form.setValue('incident_state', 8);
    g_form.setValue('state', 8);
 
   
gsftSubmit(null, g_form.getFormElement(), 'Canceled'); //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')
    serverResolve1();
 
function serverResolve1() {
    current.incident_state = 8;
//    current.close_codes = 'Cancel Incident by Caller';
    current.update();
    action.setRedirectURL(current);
 
}

 

1 ACCEPTED SOLUTION

@Ankita Gupte 

UI actions created on table are shown on form

You cannot show client side UI action i.e. Client checkbox=true in portal form view.

you can use only server side UI action on portal

So make your UI action as server side and it will work both in native+ portal form view

Uncheck client checkbox and remove Onclick field

if(current.comments == ''){
	gs.addErrorMessage("Please populate comments");
	return false;
}
else{
	current.incident_state = 8;
	current.state = 8;
	current.update();
	action.setRedirectURL(current);
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ahmmed Ali
Mega Sage

Hello @Ankita Gupte 

 

Basically UI action works at both Server and client side. The checkbox "client" in the UI action form tells if any client side function needs to be run if the UI action is clicked. When client checkbox is checked, new field will be visible where you need to give function name which runs at client side.

 

In your UI action, make the client as true, and give cancelIncident() as onclick function. Then use below script in UI action script:

 

//Below is client function which runs on click
function cancelIncident() {
    //Set the 'Incident state' and 'State' values to 'new/assign/inprogress/onhold', and display mandatory fields
   if(!g_form.getValue("comments")){
g_form.showErrorMessage("Comments mandatory!");
return false;
}
gsftSubmit(null, g_form.getFormElement(), 'Canceled'); //MUST call the 'Action name' set in this UI Action
}
 
//Code that runs without 'onclick' - This code basically runs after client function or if client is not checked
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    serverResolve1();
 
function serverResolve1() {
   current.incident_state = 8; //validate if 8 is value for cancelled state
current.state = 8;
    current.close_codes = 'Cancel Incident by Caller';
    current.update();
    action.setRedirectURL(current);
 
}
 
Validate the syntax
 
 
Thanks,
Ali
If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi Ali,

Thank you for quick update but when I click on client as true then the UI action is not visible on Service Portal

 

AnkitaGupte_0-1694684473134.png

 

Hi @Ankita Gupte 

 

Are you using form page in portal or standard ticket page, to show the incident to end users?

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Ankita Gupte
Kilo Sage

Hi Ali we are using it on ticket form

AnkitaGupte_0-1694699766340.png