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

@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

Ankita Gupte
Kilo Sage

Thank You @Ankur Bawiskar. You are a star