cancel button on change task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:46 AM
Hello
I want to create cancel button on change task which will cancel the change task .
It should make worknote field mandatory and add pop up whenever user tries to cancel the change task

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 12:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 02:01 AM - edited 04-29-2024 02:01 AM
Hi @harry24 ,
- 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
- 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('work_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 work_b otes 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.
- Save the UI Action and test it on the form.
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 03:31 AM
can you help me with below code
function cancelChangeTask() {
if (confirm("You need to add a worknote with a cancellation reason while cancelling change task.")) {
// Set work notes field as mandatory
g_form.setMandatory('work_notes', true);
g_form.setValue('state', 7);
// Save the record
gsftSubmit(null, g_form.getFormElement(), 'cancel');
}
}
this is not working as expected after user enters worknote value it does not save form automatically also on clicking the cancel button again it does nothing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 03:36 AM
function cancelChangeTask() {
if (confirm("You need to add a worknote with a cancellation reason while cancelling change task.")) {
g_form.setMandatory('work_notes', true);
if (g_form.getValue('work_notes')) {
g_form.setValue('state', 3); //if Cancelled' state is by 3
gsftSubmit(null, g_form.getFormElement(), 'cancel');
} else {
alert("Please add a worknote.");
}
}
}
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....