Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Link To Destination/Event Mapping Opening Multiple Tabs

y-allen
Tera Contributor

Hello again.

 

I am working on a workspace for a few executives in our organization. In the body of the home page, I have a list that contains reference fields. The users will need to click on the reference links to view the record and act on it.

 

I am using the "reference link clicked" event mapping with the "link to destination" event handler. I am scripting the event to obtain the table and sys_id of the record to redirect the user to the classic view. However, after entering and saving this configuration, I preview the page and test the redirect, but it opens multiple tabs of the same record, and sometimes, the last page I viewed.

I have deleted and recreated the event mapping and event handler, but then even more pages open.

I have also attempted to view the backend records to see if my deleting the event mapping and event handler are still present in the logic to explain this behavior, but I have not successfully identified the table/record where this information is held.

This is the script I am using in the link to destination even handler:

 

function evaluateEvent({api, event}) {

const table  = event.payload.table;
const sysId = event.payload.sys_id;

const url = (table && sysId)
    ? `/nav_to.do?uri=${encodeURIComponent(`${table}.do?sys_id=${sysId}`)}`
    : null;

return {
    external: url ? { url } : null
};
}
1 ACCEPTED SOLUTION

lauri457
Giga Sage

The event handler mappings are in the page definition [sys_ux_macroponent] and the screen [sys_ux_screen] if I'm not mistaken.

 

What happens if you use another event handler on the same event instead? Say create a client script that just console.logs the event. Will it print multiple times? 

View solution in original post

3 REPLIES 3

lauri457
Giga Sage

The event handler mappings are in the page definition [sys_ux_macroponent] and the screen [sys_ux_screen] if I'm not mistaken.

 

What happens if you use another event handler on the same event instead? Say create a client script that just console.logs the event. Will it print multiple times? 

y-allen
Tera Contributor

I did try using a client script, but clicking a reference link did nothing. However, I should be able to console.log results in our testing environment. This isn't allowed in our unclass environment. 

 

Thank you for the information tho. I will make sure to report back my results.

y-allen
Tera Contributor

Okay. The UX Screen record was causing the issue. I was able to locate multiple relays that were triggering on every redirect call, which caused multiple windows to open. Removing the additional relays and leaving only one solved the issue. Thank you @lauri457 for helping me locate that table.