- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 12:31 AM
Hello everyone!
Can someone please help me with my attached script that is not working.
My requirement is to create a "Save" UI action that will allow users to save a form without populating all of its' mandatory fields. There are 4 mandatory fields that are all set by a UI Policy based on the form "type" field (type = 'validation_sign_up'). I want to be able to Save the form:
GIVEN that the form type is "Validation Sign Up" (validation_sign_up)
AND mandatory fields Assignment Group ('assignment_group') and Assigned to ('assigned_to') are populated.
and remaining mandatory fields: Contact Phone ('contact_cell_number') and Validation Type ('validation_type') are NOT populated.
My action name is: sysverb_update_and_stay
My condition is: current.CanWrite()
My script is below. Please assist.
saveRecord();
function saveRecord() {
//If form type is Validation Sign Up
if (current.type == 'validation_sign_up') {
g_form.checkMandatory = false; //override mandatory fields
g_form.setMandatory ('assignment_group', true); //But keep assignment group mandatory
g_form.setMandatory('assigned_to', true); //Also keep assigned to mandatory
}
}
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
action.RedirectURL(current);
current.update();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 12:45 AM
Hi,
Update as this
Client checkbox - True
Onclick - saveRecord()
Script:
function saveRecord() {
//If form type is Validation Sign Up
if (g_form.getValue('type') == 'validation_sign_up') {
g_form.checkMandatory = false; //override mandatory fields
g_form.setMandatory('assignment_group', false); //But keep assignment group mandatory
g_form.setMandatory('assigned_to', false); //Also keep assigned to mandatory
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
}
}
if(typeof window == 'undefined')
runServerCode();
function runServerCode(){
current.update();
action.setRedirectURL(current);
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 01:26 AM
I actually got it to work by adding a few extra lines of code to the script so that it looks as below and it works exactly the way that I need it to now.
function saveRecord() {
//If form type is Validation Sign Up
if (g_form.getValue('type') == 'validation_sign_up') {
g_form.checkMandatory = false; //override mandatory fields
g_form.setMandatory('assignment_group', false); //But keep assignment group mandatory
g_form.setMandatory('assigned_to', false); //Also keep assigned to mandatory
g_form.setMandatory('validation_contact_cell_number', false);
g_form.setMandatory('validation_type',false);
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
}
}
if(typeof window == 'undefined')
runServerCode();
function runServerCode(){
current.update();
action.setRedirectURL(current);
g_form.setMandatory('validation_contact_cell_number', true);
g_form.setMandatory('validation_type',true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 12:45 AM
Hi,
Update as this
Client checkbox - True
Onclick - saveRecord()
Script:
function saveRecord() {
//If form type is Validation Sign Up
if (g_form.getValue('type') == 'validation_sign_up') {
g_form.checkMandatory = false; //override mandatory fields
g_form.setMandatory('assignment_group', false); //But keep assignment group mandatory
g_form.setMandatory('assigned_to', false); //Also keep assigned to mandatory
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
}
}
if(typeof window == 'undefined')
runServerCode();
function runServerCode(){
current.update();
action.setRedirectURL(current);
}
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 01:19 AM
Hi Ankur,
Thank you so much for your help with this. I think it's soo close but it seems that the line to override the mandatory fields are not working because when I go to save the form the validation type and contact phone fields are still mandatory and giving me the warning that the fields are mandatory. Can you please tell me how to get around that issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 01:26 AM
I actually got it to work by adding a few extra lines of code to the script so that it looks as below and it works exactly the way that I need it to now.
function saveRecord() {
//If form type is Validation Sign Up
if (g_form.getValue('type') == 'validation_sign_up') {
g_form.checkMandatory = false; //override mandatory fields
g_form.setMandatory('assignment_group', false); //But keep assignment group mandatory
g_form.setMandatory('assigned_to', false); //Also keep assigned to mandatory
g_form.setMandatory('validation_contact_cell_number', false);
g_form.setMandatory('validation_type',false);
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
}
}
if(typeof window == 'undefined')
runServerCode();
function runServerCode(){
current.update();
action.setRedirectURL(current);
g_form.setMandatory('validation_contact_cell_number', true);
g_form.setMandatory('validation_type',true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2022 02:09 AM
There are few things in your script which are wrong
in the server side function code you cannot use g_form object as g_form is client side and hence won't work in server side.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader