- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 02:34 AM
Hi Guys
I have a form widget, in that we are going to be creating records from. I can get my form on page fine, using sys_id=-1.
It is quite a lengthy form so therefore they required a save as draft and submit button. Using a record producer is prob out of the question now as they want to save as draft and come back later to complete.
I cloned the form widget and looked at the html part and could get the submit button added
However, what i need is, if save is clicked, then remove the required field stamp and save the record as a draft. I have a draft state in my form. My coding experience is pretty low, especially on the portal side
Any Pointers or anyone do this before?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 06:41 AM
You could try this, Brendan.
HTML Button near the bottom of the form:
<button type="button" ng-click="saveAsDraft()" class="btn btn-primary action-btn pull-right">
Save as Draft
</button>
Method added to the Client Script (controller), just before the last brace.
$scope.saveAsDraft = function() {
for (var x in $scope.data.f._fields) {
g_form.setMandatory(x, false);
}
$scope.triggerUIAction($scope.getPrimaryAction());
}
The saveAsDraft function gets all of the fields on the form, sets them as not mandatory, then triggers the save.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 06:41 AM
You could try this, Brendan.
HTML Button near the bottom of the form:
<button type="button" ng-click="saveAsDraft()" class="btn btn-primary action-btn pull-right">
Save as Draft
</button>
Method added to the Client Script (controller), just before the last brace.
$scope.saveAsDraft = function() {
for (var x in $scope.data.f._fields) {
g_form.setMandatory(x, false);
}
$scope.triggerUIAction($scope.getPrimaryAction());
}
The saveAsDraft function gets all of the fields on the form, sets them as not mandatory, then triggers the save.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2017 08:11 AM
Justin, thanks very much, that worked well. I was about to give up on it!
One point, it does not remove required for fields that are set mandatory on dictory, it does for fields with UI policy setting them, but i can work with that. Again, thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 04:02 AM
Hi Justin
Got another question and wondering if you could help. So i have my form loaded into form widget and got the save as draft working- thank you.!
On the out of box save button can i change the status on my form to Submitted? I have used the form widget and placed sys_id=-1 to load a new record each time, once all fields completed and saved, the status should change to submitted.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2017 05:31 AM
In the $timeout, just before the g_form.submit, you could try building logic to check if it's a new record and NOT a draft, then set the state to submitted:
$timeout(function() {
if (g_form) {
if (g_form.isNewRecord() && g_form.getValue('state') != 'YOUR_VALUE_FOR_DRAFT') {
g_form.setValue('state', 'YOUR_VALUE_FOR_SUBMITTED');
}
g_form.submit(action.action_name || action.sys_id);
}
});
But it might be wiser to handle that with a business rule on the back-end. Something like, on insert, if State is not Draft, set State to Submitted.