Setting g_form.setMandatory to false not working in Service Portal?

patricklatella
Mega Sage

Hi all,

I've got a button widget I'm using on a record producer that allows the user to click the button to turn all the mandatory fields to not mandatory (this then allows the user to save a "draft" copy of the created record...this is on a custom table not extended from task).  The button appears to be working...I click the button and the mandatory field indicators for the existing mandatory fields go away.  However when I go to submit the form, the form does not submit...the typical error shown when mandatory fields are not filled in does not show.  However when viewing the console in Chrome DevTools it shows that the submission of the form failed because mandatory fields were not filled in.  Is this a bug in ServiceNow?  Or is there a better method for setting the fields to mandatory = false?  Thanks!

Here's my client script on the widget.

function($scope){

var c = this;
var g_form = $scope.page.g_form;

console.log(g_form);
var arr = g_form.getFieldNames(); 
console.log(arr);

c.saveDraft = function() {

for (var i in arr) {
var field = arr[i];
g_form.setMandatory(field,false);
}

var check = g_form.submit();

alert(check);

};

}

12 REPLIES 12

yes, the issue issue is caused by someother code, $scope.page.g_form.setMandatory('variable',false); is working as expected.

 

 

Thanks Satheesh...I'll keep digging.

Are you on the same release/Patch level as your client as well?

 

//Göran

Another solution for this would of course be to not use the submit etc. But have a custom button that doesn't care about the mandatory fields and pretty much takes the data and saves it where ever you save your draft versions.

 

//Göran

patricklatella
Mega Sage

Hi Göran,

thanks for the replies...I guess the version could be part of it...my client is on Jakarta (Build tag: glide-jakarta-05-03-2017__patch9c-08-09-2018)...and my developer instance is Kingston.

That said, as you mention, ultimately the goal is for my "Save as draft" button to submit the form and create the record on the custom table.  So another question is why the submit() part of my script isn't work in either the client's instance nor my developer instance.

any ideas?