Creating Links to Multiple Instances of the Same Route in UI Builder

Picture the following scenario:

You’ve created a record page in UI Builder and hooked up a “New Record” button linking to it on your home page. You open the page and test itonce by clicking it, filling out the new record form, and submit. It works great!

Now, you go to test it again, however when you click the button on the home page for a second time, instead of being presented with a brand new form, all the values from the previous submission are still there! What is going on?!

What you’re experiencing is UI Builder creating only a single instance of a particular route. The standard practice when creating a record page in ServiceNow is that it has a sysId parameter. When opening an existing record that parameter will have a sys ID of an actual unique record passed in. However, in the case of a new record, the sys ID that gets traditionally passed in is -1.

In the above scenario, both times that the “New Record” button was pressed would have resulted in a route such as the follows being opened: /record/incident/-1.

Because the route and it’s parameters is identical, instead of creating a new instance of the new record page, it simply presented the user with the old one, hence why all the values from the previous submission were still in there.

This behaviour of only creating a single instance of a page can be controlled using the multiInstField parameter of the “Link to destination” event handler (labelled as “Multi-instance field (advanced)” in “Form” mode).

In our scenario above, if we were to supply it with the value sysId then that page parameter will be used as the field that ensures that multiple instances of the same page will be created.

Now, when clicking the “New Record” button…

  • On the first click we will be directed to the following route:
    /record/incident/-1_uid_1
  • On the second click, we will be directed to the following route.
    /record/incident/-1_uid_2
  • Subsequent presses will also result in further increments of this unique ID

Because for each click of the button the unique ID at the end of the parameter is being incremented, we will be directed at a new instance of the New Record page.

Even though the sysId parameter in the URL in these scenarios is no longer -1 but is instead something like -1_uid_1, it doesn’t matter as the unique ID component will be automatically stripped and will not make its way back to the screen.

Here’s an example of how it might be setup using the “Link to destination” action handler in UI Builder:

The multiInstField parameter can be a little confusing at first as to what its purpose is, however as you can see it is very useful and will surely be needed in many different UIB experiences created by developers.