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