How to get a widget (button) to set mandatory fields on a catalog item to not mandatory and submit "Draft" state of the form in Service Portal?

patricklatella
Mega Sage

Hi all,

I've got a record producer I'm fixing to work in Service Portal.  The form has a number of mandatory fields.  I've built a widget to put a "Save as Draft" button on the form.  When the user clicks the button, they are prompted with an alert.  When they click "OK", I need any mandatory fields on the form to change to "mandatory = false", and then for the form to submit as normal, creating a new ticket on the target table with a custom "u_status" field set to "u_draft".  Any help would be great, thanks!

Here's my client script in my widget:

function($scope, $rootScope, $timeout){

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

var arr = g_form.getFieldNames();

//need something here to get "arr" down to only fields that are mandatory...how to do this?

c.saveDraft = function(){
alert('Are you sure you want to save as Draft?');
$scope.page.g_form.setMandatory(arr,false);//needs to set the fields that mandatory on the form to not mandatory
g_form.setValue('u_status','u_draft');
alert('should save now');
$timeout(function() {
//$scope.page.g_form.checkMandatory = false;
$("[name='submit']").trigger('click');
});
return true;
}
}

1 ACCEPTED SOLUTION

patricklatella
Mega Sage

I figured it out.  Here's my script:

 

function($scope, $rootScope, $timeout){

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

var arr = g_form.getFieldNames();

c.saveDraft = function(){
alert("Are you sure you want to save the form?");
for (var i in arr) {
var field = arr[i];
$scope.page.g_form.setMandatory(field,false);
}
g_form.setValue('u_status','u_draft');

$timeout(function() {
$("[name='submit']").trigger('click');
});
return true;
}
}

View solution in original post

3 REPLIES 3

patricklatella
Mega Sage

I figured it out.  Here's my script:

 

function($scope, $rootScope, $timeout){

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

var arr = g_form.getFieldNames();

c.saveDraft = function(){
alert("Are you sure you want to save the form?");
for (var i in arr) {
var field = arr[i];
$scope.page.g_form.setMandatory(field,false);
}
g_form.setValue('u_status','u_draft');

$timeout(function() {
$("[name='submit']").trigger('click');
});
return true;
}
}

Hi Patrick Could you please share your server side script also . I am trying to add a button on record producer form in service portal . It should create a record and set the status to draft so that the user can edit the variables before he can submit the ticket

Hi Patrick can you please share your whole widget. I am having the same requirement and i dont have any clue about angular js . Please help me