- 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
12-12-2023 01:24 PM
Thanks Ankur! This saved my life LOL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 12:47 AM
Please find the below thread ...hope it helps you
Thanks,
Bhavya