Brian104
Tera Expert

A common scenario when building web applications is to provide a form for users to enter data into and submit that data.   This is quite simple to do in ServiceNow using out of the box items such as a Table, Service Portal, Service Portal Page and the Form Widget.  However, when you want to make a form that is publicly available to non-authenticated users, in a scoped application, it can get a bit tricky.   Have no fear though as this task is still fairly straight-forward (well at least the way I've figured out how to do it.).  At a high level, all you need to do is the following:

  1. Create a Table for the form data and grant the built in "public" ACL role access to the table
  2. Create a Service Portal
  3. Create a "public" Service Portal Page
  4. Clone the global Form Widget into your application scope
  5. Modify the Server Script by replacing global function calls with scoped function calls

NOTE:  You can skip step five if you are building a global application; at least I think (I haven't verified because I only build scoped applications)

NOW (see what I did there) lets go through each step in a little bit more detail:

Creating a Publicly Accessible Table

Creating a table and making it accessible to anyone on the internet is quite simple since ServiceNow provides an out of the box "public" role that you can use when you setup your ACLs on the table.  To do this, go to the "Controls" tab on your table and add the "public" role.

 

find_real_file.png

 

Creating a Publicly Accessible Service Portal Page

The next step is to create a Service Portal Page that anyone can access.  I won't go about how to create a Service Portal or the actual Page, but instead just tell you how to make the page public.   It's actually quite easy, you click on the "Edit Page" gear option and check "public":

find_real_file.png

Once you've got your page created, the next step is adding a custom form widget to display your form to the public.

Creating a Public Form Widget

Note:  This could possibly be accomplished by simply making the global Form widget public, but I haven't been able to explore this yet.

So the first thing you need to do is clone the existing Form widget.  You'll want to do this so that you can use all of the out of the box functionality that this widget provides (i.e. auto display all form fields, validation, etc) and also so that you don't have to make the global Form widget public.

Once you've cloned the widget, there are a couple lines of code that reference global functions, which are not accessible to scoped applications.  If you don't believe me, just clone the widget, add it to your scoped application portal page and load it 🙂

The main culprits are the following functions:

  • GlideTableDescriptor
  • $sp.getRecord
  • GlideDBObjectManager

Each of these can be replaced using the following scoped functions:

  • GlideTableDescriptor.isValid()  => GlideRecord.isValid()
  • $sp.getRecord => new GlideRecord()
  • GlideDBObjectManager => GlideTableHierarchy()

Below I've highlighted where I've made these substitutions.

find_real_file.png

 

And with that, wala!  You now how a form that displays to the public with minimal coding!

Version history
Last update:
‎05-13-2022 03:32 PM
Updated by: