- 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
02-01-2023 09:53 AM
You can't do that especially when you set mandatory in the dictionary. That is saying it is always mandatory. I'm not sure I understand the logic. What is the point of a mandatory field if you can just bypass it when clicking save. It doesn't seem like it is a mandatory field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 12:35 PM - edited 02-02-2023 12:36 PM
You cannot do that. Because you have mandatory at the dictionary level as soon as the form reloads from the asterisk will reappear. Whey do you even have a mandatory field the is technically not mandatory if you hit save?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 12:37 PM
Yes, based on the code I provided it allows to save without satisfying the fields. I performed this on multiple forms using the same code. It worked.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 03:25 PM
Still does not make sense to me. Why make the field mandatory if you can bypass it. Might as well just not have a mandatory field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 05:30 AM
I just didn't include a code in there where it needs to update a field status to certain value each time the button is clicked.