Ui Action Cancel Button

Sushant20
Tera Contributor

Hi All,

 

Can any one please help with the requirement.

When a user cancels , the pop-up should require a in that popup only  user to input a cancellation reason.
- and that comment popup should be mandatory when we click on cancel.
- after that it  should be added to the work notes

 

Thank you.

2 REPLIES 2

Dom Gattuso
Mega Sage

On the the UI Action:

Action name: cancel_request

Client: true

Onclick: confirmCancel()

 Ui action script: 

function confirmCancel(){
	if(confirm('Are you sure you want to Cancel?')){
		var reason = prompt("Why do you want to cancel?");
		if(reason){
			//If you wish to capture the reason on the record
			g_form.setValue('<field>',reason);
		}
		gsftSubmit(null,g_form.getFormElement(), 'cancel_request'); //UI Action > Action name
	}else{
		return false;
	}
}


if(typeof window == 'undefined'){
	cancelRequest();
}

/**
* Cancels the record and reloads the page
*/
function cancelRequest(){
	action.setRedirectURL(current);
	

 

Rajesh_Singh
Kilo Sage
Kilo Sage

@Sushant20 

 

  1. Create a new UI Action:
  • Go to the Form Layout for the record you want to modify (such as the Incident or Request form)
  • Click on the UI Actions related link
  • Click on New to create a new UI Action
  1. Configure the UI Action:
  • Set the Name of the UI Action, such as "Cancel with Reason"
  • Set the Table to the record type you want to modify (such as Incident or Request)
  • Set the Action Name to "Cancel"
  • In the Script field, enter the following code:
if (confirm('Are you sure you want to cancel this record?')) {
  var reason = prompt('Please enter a cancellation reason:');
  if (reason) {
    g_form.setValue('close_notes', reason);
    gsftSubmit(null, g_form.getFormElement(), 'cancel');
  } else {
    alert('A cancellation reason is required.');
  }
}

This code will display a confirmation dialog when the Cancel button is clicked, and prompt the user to enter a cancellation reason in a pop-up dialog. If the user enters a reason, the reason will be set as the value of the close_notes field (which is the work notes field for some record types), and the record will be cancelled. If the user does not enter a reason, an alert message will be displayed.

  1. Save the UI Action and test it on the form.
If you found my response helpful or applicable, please consider marking it as correct or helpful to assist others who may be seeking the same information.

---------------
Regards,
Rajesh Singh