Build a Draft Button for a form with many mandatory Fields (checkMandatory)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 01:21 AM - edited 07-08-2024 01:34 AM
We have a form with 25+ mandatory Fields.
We wannt to have a Draft Option.
i tried this in a ui action:
function save_draft() {
g_form.checkMandatory = false; //override mandatory fields
gsftSubmit(null, g_form.getFormElement(), 'save_draft_server');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined') {
current.update();
action.setRedirectURL(current);
}
But it does not work. I always get the Message that Mandatory Fields are missing and no value is saved.
Is there an Option to do this?
Update: maybe solved with the answer out of this Question:
https://www.servicenow.com/community/developer-forum/saving-records-without-populating-mandatory-fie...
function Saved() {
alert("checking");
g_form.checkMandatory = false ;
gsftSubmit(null, g_form.getFormElement(),'saved');
//g_form.save();
}
action.setRedirectURL(current);
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 02:45 AM
Hi @Meloper
Please don't do this. We tried something similar and the system performance get impacted very badly. Reason be, for user it is just a draft but for system, every click on this draft button will create a new row/ record in backend to save the changes and now just imagine, if a user click 5-10 times draft button how many time records get saved in DB and while retrieval same issue happened.
Not a good requirement better to move this to catalog item and use OOTB save as draft but dont do this on native form view.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 03:28 AM - edited 07-09-2024 03:28 AM
I solved it with this script.
This was mentioned in a comment there
https://www.servicenow.com/community/developer-forum/saving-records-without-populating-mandatory-fie...
guess there is no Problem, because i only make the field not mandatory.
the Draft Option in Portal is a different approach
function save_draft() {
var i;
var arrValues = g_form.getMissingFields().toString().split(',');
// checking existance of value
for (i = 0; i < arrValues.length; i++) {
g_form.setMandatory(arrValues[i], false);
}
gsftSubmit(null, g_form.getFormElement(), 'save_draft_server');
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined') {
action.setRedirectURL(current);
current.update();
}