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 11:53 AM
I think part of the problem is that it does not appear to be making it past this function:
c.saveDraft = function() {
for (var i in arr) {
var field = arr[i];
//g_form.setMandatory(field,false);
$scope.page.g_form.setMandatory(field,false);
}
I put an alert in there just before the end and the form got stuck in the infinite alert loop (ugh!)
But in the end, it's not making it to this part of the script:
$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 01:43 PM
I usually don't play around so much with the g_form way in a widget. done it a few just since it there from the start. But So in this case I would probably use my custom "save as draft" to save the record in your custom table my a easy server call instead and sending over all the data and then save it with a normal gliderecord query.
Here is one sample using the server.update() to do it:
Communicating between the Client Script and the Server Script of a widget
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2018 03:46 PM
Hi Göran, do you have an example of your custom "save as draft" script?