Save as Draft Solution for Form with Initiator set to Anonymous User

AnonymousSaveDraft.nitro_s

As many of you may know, FEB has a Save as Draft feature.  This feature, as of 8.6, has a limitation where you can only save a draft if you are an authenticated user.  This is a logical limitation as FEB needs to know who the user is in order to associate the draft to them.

I had a request for a Save as Draft feature for an anonymous survey.  I put some thought in to a solution and I wanted to document it here for anyone else that might be interested in such a feature.

Solution Description

The end solution from the user perspective can be described as:

The user is filling out the form and realizes they need to step away from the computer so they click the Save as Draft button.  A prompt will appear where they enter an email address (unvalidated).  They will receive an email that contains a link to the draft, clicking on that link will launch the draft form and they can continue filling out the form.

Implementation Details

There are only a few pieces to this solution which makes it pretty easy to implement in your application.

  1. Add a hidden field that will store the user's email address.  This field is used to populate the To field of the email that gets sent.  The field is hidden by javascript in the form onLoad event (i.e. item.setVisible(false))
  2. Add a Stage that will hold the "drafts".  Create a "Submit button" and give it a title of "Save as Draft" and an ID of "S_SaveAsDraft" and have it point to the Draft stage (It is important that this is a Submit button and not a Draft button).  If you want user's to be able to continually save the draft then add another submit button to the draft stage as well and it will point back to the Draft stage (In my example I labelled this button Update Draft). 
  3. Setup an email to be sent on the Save as Draft submit button.  Link the To field to the Email for draft field that you created.  In the body of the email add whatever descriptive text you want but then include an Invite Link which you can access from the Insert Item menu. The invite link is a special url that contains a unique code that will allow the user to access this record once it has been submitted.
  4. We need to define the access permissions.  On the Access tab, select the Record Owner role, remove the Instance Creator group and add Invited Users. Then in the draft stage make sure that the Record Owner role has Read and Update permission.
  5. If your form has required fields then you will have to use javascript to make them required rather than using the required property.  In the form onLoad event you can set a field to required by using the following JavaScript:

    BO.F_SingleLineEntry.setRequired(true);
     
  6. Now for the little bit of javaScript required to glue it all together.  In the Application...Settings...Events (in 8.6.2 - click the properties of the form, click the Events tab and click the onLoad event) add the Recursive Function from the Wiki. Set your processItem function to:

    app.getSharedData().processItem = function(item) {
      if(item.getBOAttr() !== null) {
        //turn off the required state of the field
        item.getBOAttr().setRequired(false);
      }
    }



    In the form validateButtonPressed event add the following code:


//show dialog to capture users email to send link to form
if(pButtonTitle === "S_SaveAsDraft") {

//set all required items to not required
  app.getSharedData().getItem(form, app.getSharedData().processItem);


  var userEmail = prompt("Provide Email Address, an email will be sent with a link to access this draft");
  var r = false;
  if (userEmail !== null) {
    BO.F_SingleLine0.setValue(userEmail);
    r = true;
  }
  return r;
}


Limitations

  1. If the user enters an invalid email address then they will not receive the email and will not be able to access their survey.
  2. Anyone with access to the link that is sent in the email can access the survey

A sample application, built in 8.6, is attached to this article.