Save Button on form to ignore mandatory fields and save
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 08:26 PM
Hi everyone!
I need to create a Save button that will appear on a form and save the record even if some mandatory fields have yet to be filled. The button should ignore the required fields and save the form.
Or
I need to create an alert message which will ask the user to save the details. If we click on Ok or Save on that alert, it should save the details on the form ignoring empty mandatory fields if there are any.
Let me know if you have any thoughts on this!
Thanks in advance,
Amol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 09:07 PM
Hi @Amol Pawar ,
Use below code in your UI action (Save As Draft). You need to make ui action client callable.
var confirm = Confirm('Are you sure?');
if(confirm){
var fields = g_form.getEditableFields(); // Get all fields on the form
fields.forEach(function (field) {
g_form.setMandatory(field, false); // Make each field non-mandatory
});
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2024 09:10 PM
Hello @Amol Pawar ,
Try following UI Action script
function makeConfirmation() {
var answer = confirm('Do you want to save form? This ignores mandatory fields! ');
if (answer) {
var fields = g_form.getMissingFields();
for (var i = 0; i < fields.length; i++) {
g_form.setMandatory(fields[i], false);
}
gsftSubmit(null,g_form.getFormElement(),'save_ignore_required');
}
}
if(typeof window == 'undefined'){
saveIngoreMandatory();
}
function saveIngoreMandatory(){
current.update();
action.setRedirectURL(current);
}
it is working fine for me, make changes according to your requirements
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2024 04:03 AM
Hi @RAMANA MURTHY G,
Thank you for your response first of all!
I tried with your solution but that button itself is not visible on the form. Let me know if I'm missing anything checking these snapshots:
Thanks in advance,
Amol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2024 11:00 PM
Hello @Amol Pawar ,
It looks like everything is fine, I can't find any mistake in it, the button should be visible on the form, make sure the Application scope is correct or not and try to change the order value and check.
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2025 04:52 PM
It won't be visible on the portal side