Help with UI Action to save a form without populating mandatory fields

Still Learning
Kilo Sage

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();

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

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);
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

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);

}

View solution in original post

6 REPLIES 6

Thanks Ankur! This saved my life LOL.

Bhavya7
Tera Contributor