Setting g_form.setMandatory to false not working in Service Portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 10:14 AM
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);
};
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 10:30 AM
Hi ,
your code should be working fine, but not sure why it was failing.
try
$scope.page.g_form.setMandatory(field,false);
if above not worked try the below
Use this just before the save or submit.
$scope.page.g_form.checkMandatory = false;
Thanks,
satheesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 10:32 AM
Thanks Satheesh for the response...I'll try that now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 10:38 AM
hmmm...still now working in my client's instance. Here's my updated code. This button should also submit the form, correct?
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);
$scope.page.g_form.setMandatory(field,false);
}
$scope.page.g_form.checkMandatory = false;
var check = g_form.submit();
alert(check);
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2018 10:32 AM
I've built a version of this widget in my personal developer instance, and the logic that is removing the mandatory bit is working...and as well I can submit the form (but only with the OOTB submit button on the add to cart widget). So my issue with it not working may have something to do with my client's instance? Any ideas to troubleshoot?