Cancellation click states changes to cancelled

NunnaB
Tera Contributor

 

When a Cancellation button is created in Workspace for cases in the Ready, Work in Progress, or Closed Complete states, clicking the Cancellation button should display a popup asking the user to enter a cancellation reason.

If the user clicks Cancel without entering a cancellation reason, an error message should appear stating that the cancellation reason is required.

After entering the cancellation reason and submitting successfully, the case state should automatically change to Cancelled and the case should be saved with the Cancelled state. But when I try with some code the state changes to cancelled but not saving state it's shaved with old value  

1 REPLY 1

Tanushree Maiti
Tera Patron

Hi @NunnaB 

 

Try this,

 

Configure your UI Action with the following fields:

  • Name: Cancel Case
  • Action name: cancel_case_workspace
  • Table: <your table name>
  • Active / Form button: Checked
  • Client: Checked
  • Onclick: openCancellationModal()
  • Condition: current.state == 1 || current.state == 2 || current.state == 3 (update condition as per your requirement
  • Workspace Form Button: Checked (under the Workspace tab)

Sample code/Not tested: 

function openCancellationModal() {
g_modal.prompt({
title: 'Cancel Case',
label: 'Please enter a cancellation reason:',
value: ''
}).then(function(result) {
if (result.status === true) {
var reason = result.value ? result.value.trim() : '';
if (!reason) {
g_form.addErrorMessage('The cancellation reason is required.');
return false;
}
g_form.setValue('u_cancellation_reason', reason);
g_form.setValue('state', '7'); //replace with your cancelled state
g_form.save();
} else {
return false;
}
});
}
if (typeof window == 'undefined') {
action.setRedirectURL(current);
}

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti