UI Builder: "Link To Destination" and "NAV_ITEM_SELECTED" Events Not Working for New Records.

DEV 1
Tera Contributor

Description:
I am working on a UI Builder page where I need to redirect users from a subpage (e.g., "kb_view") back to the record page (e.g., "incident") when a specific action occurs. This works for existing records but not for new records where the sys_id is in the format "-1_u_1".

What I Tried:

  1. Using "Link To Destination":
    Attempted to configure navigation via "Link To Destination," but it does not work for new records.
  2. Using the NAV_ITEM_SELECTED Event:
    Below is the script I used:

    const redirectPayload = {
  3.     redirect: true,
  4.     route: "record",
  5.     fields: {
  6.         table: "incident",
  7.         sysId: api.state.parentTabRecordId, // sys_id of the new record
  8.     },
  9. };
  10. // Emit navigation event to redirect the user to the incident record
  11. api.emit("NAV_ITEM_SELECTED", redirectPayload);
    Unfortunately, this also does not work for new records.

Goal:

I need a reliable way to redirect users from the "kb_view" subpage back to the "record" page, regardless of whether the sys_id belongs to an existing record or a new record (e.g., "-1_u_1").

Questions:

  1. Is there a specific configuration or workaround to handle navigation for new records in UI Builder?
  2. Does NAV_ITEM_SELECTED support this use case, and if not, what alternative approach should I use?
  3. How can I ensure compatibility for both existing and new records when using navigation events in UX client scripts?

 @Brad Tilton 

Any insights or suggestions would be greatly appreciated.

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Routing the user to a record that is already open in a tab should always just refocus that tab instead of opening a new tab. If there is already a tab open for a new record you should be able to just refocus that tab by removing the _u_1 from the url.

Basically, the way the routing works for the workspace app shell is that if you're opening a url that already exists in a tab it just takes you to that tab, if the url doesn't already exist it opens a new tab. For new records, the _u_1, _u_2 is appended to the -1 sys_id value in order to make the url unique and force new records to open in a new tab.

I'm not exactly sure if what you're trying to do is possible, but hopefully this helps explain things a bit.

 

  • I am working on configuring a button on the KB_View page (when a knowledge article is opened via Agent Assist in full view). The goal is to set specific fields on the Incident form, similar to how a template works. Here's the current situation:

    1. Current Approach:

      • I am passing the sys_id of the template through the URL using "Link to Destination Record."
      • On the record page, I created an event handler to parse the URL, retrieve the template ID, and apply it to the record page using the "on page property change" event.
    2. Issues Encountered:

      • This approach works only for existing records (those with a sys_id).
      • When trying to redirect to create a new Incident record, it opens a new tab in the workspace with a "Record Not Found" message.
    3. Questions:

      • How can I establish client-side communication between the KB_View page (knowledge sub-page) and the controller on the Incident record page to pass data or interact dynamically?
      • For redirecting to a new record, how can I avoid the "Record Not Found" error and prefill the form fields?
      • Is there a way to refocus an already open tab (even for new records) using a UX client script?
      • How can I implement this tab-refocusing behavior through a UX client script, especially for new records?

@Brad Tilton 

 

 

Screenshot 2024-12-23 at 10.24.30 PM.png

 

 

Screenshot 2024-12-23 at 10.32.49 PM.png

Any suggestions or thoughts? @Brad Tilton @Ashley Snyder

For existing records, the link works correctly as the record page includes the required parameters: sys_id and table name. However, for new records, I have tried the following approaches:

  1. Using "-1": This opens the record in a new tab, which is not the desired behavior.
  2. Using "-1_u_1": This results in a "Record not found" error.

Could you please clarify:

  • How should the parameters be configured to handle new records correctly?
  • Is there an alternative approach or parameter for maintaining the intended functionality?

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you're opening a new record it's going to open in a new tab unless you already had a tab open with a -1 route. We don't really have functionality that lets you target specific tabs/routes. Generally, workspace is going to repoen an existing page in the existing tab, or open a new route in a new tab. I would not try to change the way that works or introduce a new paradigm.

 

Here's a little more on how the -1_uid_1 functionality works: https://www.dylanlindgren.com/2023/12/21/creating-multiple-instances-of-the-same-route-in-ui-builder...