- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 12:25 PM
Hi,
I am currently stuck on getting this code work.
When a Save Button is clicked, I want the fields mandatory set to false and prompt for confirmation.
When is cancelled, the fields should set it back to mandatory or new record.
When is Ok, set the form back to new
Can you help revise the code for me?
UI Action Script
function confirmationdialog() {
var answer = confirm('Ready to save?');
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'sys_update_value');
} else {
var fields = g_form.getEditableFields();
for (var x = 0; x > fields.length; x++) {
g_form.setMandatory(fields[x], false);
}
return false;
}
}
if (typeof window == 'undefined')
priorityUpdate();
function priorityUpdate() {
current.update();
action.setRedirectURL(current);
}
Expected result
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 06:35 AM - edited 02-01-2023 06:36 AM
The revised the code, I'm able to save the form without having to resolve the mandatory field. But the Mandatory asterisk symbol still visible when the Save button is clicked.
I would like the asterisk symbol is set to not visible when save button is clicked.
function confirmationdialog() {
// Get the reference to the current form
var form = g_form;
// Get an array of all the editable fields on the form
var editableFields = form.getEditableFields();
// Loop through the array of editable fields
for (var i = 0; i < editableFields.length; i++) {
// Set the current field as not mandatory
form.setMandatory(editableFields[i], false);
}
// Prompt the user for confirmation
var answer = confirm("Are you sure you want to save this form?");
// If the user clicked "OK"
if (answer) {
// Save the form
form.save();
// Show a success message
g_form.addInfoMessage("Form saved successfully");
}
// If the user clicked "Cancel"
else {
// Loop through the array of editable fields again
for (var x = 0; x < editableFields.length; x++) {
// Set the current field back to mandatory
form.setMandatory(editableFields[x], true);
}
// Show an error message
g_form.addErrorMessage("Save operation cancelled. Editable fields are now mandatory again.");
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 12:28 PM
How is the field being set to mandatory?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 12:30 PM
The mandatories are set to true in the table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2023 02:36 PM
Sounds like you have mandatory to true on the dictionary level. This means you can never make it false unless it is filled in and/or you have some other conditions to set it to false. A record save if you clear the field will not work. Does the field value clear after save? I need more info on why you want it not to be mandatory. Usually once a field is filled it the mandatory asterisk will go gray and the field had meat the requirements for being filled in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2023 06:35 AM - edited 02-01-2023 06:36 AM
The revised the code, I'm able to save the form without having to resolve the mandatory field. But the Mandatory asterisk symbol still visible when the Save button is clicked.
I would like the asterisk symbol is set to not visible when save button is clicked.
function confirmationdialog() {
// Get the reference to the current form
var form = g_form;
// Get an array of all the editable fields on the form
var editableFields = form.getEditableFields();
// Loop through the array of editable fields
for (var i = 0; i < editableFields.length; i++) {
// Set the current field as not mandatory
form.setMandatory(editableFields[i], false);
}
// Prompt the user for confirmation
var answer = confirm("Are you sure you want to save this form?");
// If the user clicked "OK"
if (answer) {
// Save the form
form.save();
// Show a success message
g_form.addInfoMessage("Form saved successfully");
}
// If the user clicked "Cancel"
else {
// Loop through the array of editable fields again
for (var x = 0; x < editableFields.length; x++) {
// Set the current field back to mandatory
form.setMandatory(editableFields[x], true);
}
// Show an error message
g_form.addErrorMessage("Save operation cancelled. Editable fields are now mandatory again.");
}
}