Adding ‘Save As Draft’ Functionality

Update: apologies but I wrote this article while clearly very tired and it doesn’t read very well! But the general gist of the functionality is there so I won’t update it, but I’ll take better care in future 🙂

This requirement has come up enough now for me to share my implementation of it on here for others.

So this requirement usually comes from the change management team when delivering change.

Change forms are generally quite long with loads of fields and options to select from, despite doing my utmost to shorten and simplify them!

In the old days of word documents and spreadsheets, an employee could download the change form and over the course of a few days, gather the right information and fill it out and submit it when they’re ready.

In ServiceNow, you generally don’t have that luxury with mandatory fields. You either submit when they’re all populated, or you don’t.

That’s where the ‘Save as draft’ option comes in.

It’s actually quite a simple solution to the problem, but I created a very simple UI action on the form called ‘Save as draft’ and made sure to click the ‘Client’ checkbox to run client script and enter ‘removeMandatoryCheckChange()’ as the onclick function. Also, give it an action name of ‘saveDraft’.

The UI action script was then as follows:

//Client-side 'onclick' function
function removeMandatoryCheckChange(){
//Remove mandatory flag from all elements
for (var i = 0; i < g_form.elements.length; i++) {
var el = g_form.elements[i];
var fieldName = el.fieldName;
g_form.setMandatory(fieldName, false);
gsftSubmit($('saveDraft'), g_form.getFormElement(), 'saveDraft');
if(typeof window == 'undefined')
//Server-side function
function saveBusinessRule(){
//Here you can set any other values that you need to do when saving
current.assignment_group = '';
current.assigned_to = gs.getUserID();
current.state = -98;

Really easy and simple, and adds a lot for the end user so they can slowly populate the form.

(side note, for the client side / server side UI action logic, you check out ServiceNow Guru’s post on how this works. That is what I’ve adapted here)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.