Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Issue with Scripted Event Handler

Community Alums
Not applicable

I'm trying to use a script in the "Link to destination" event handler.

Use case is I want a referenced knowledge article to link out using the  'kb_view'  page route instead of the 'record' routing.   Linking from a Simple List. 

I tried hardcoding the  route and field paramaters, and I couldn't get the script to link out. If I fallback to the form, then I can use either 'record' or 'kb_view', but can't make it conditional.

I've also tried using the event.payload.params.table  instead of event.payload.table and that didn't work either.

function evaluateEvent({api, event}) {

    var routeSelect = '';
    if (event.payload.table == 'kb_knowledge') {
        routeSelect = 'kb_view';
    } else {
        routeSelect = 'record';
    }



    return {
        route: routeSelect,
        fields: {
            'table': event.payload.table,
            'sysId': event.payload.sys_id
        },
        params: null,
        redirect: null,
        passiveNavigation: null,
        title: null,
        multiInstField: null,
        targetRoute: null,
        external: null
    };
}

 Thanks for any assistance.  -Aaron

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Aaron,

A couple of things here. The first is that I'm sure you know the names of your routes, but when I spin up a new workspace the default route name for the kb page is actually 'kb' rather than 'kb_view' so I would double check that to make sure.

The bigger issue is that it appears there may be a defect in San Diego around scripting the link to destination event handler where it doesn't work while using the form view does work. There is a workaround, which is to run a cache.do on your instance. I was able to replicate both this error (using your script with kb instead of kb_view) and then it worked after I cleared the cache on that instance.

Just a quick disclaimer that clearing the cache is something you want to be careful about, especially in production instances as the instance will run a little slower for a bit.

View solution in original post

5 REPLIES 5

TT3
Kilo Guru

What do you mean by "I'm trying to use a script in the "Link to destination" event handler". Are you trying to achieve that when user clicks on a KB article, it should show the article itself and not a list view?

Community Alums
Not applicable

I have a table shown in the Simple List component.   I have references fields on the table.  Most of them open fine with the 'record' route.  But instead of the standard KB article record, I want it to show the 'kb_view' route when the reference in that column is clicked instead of 'record'.

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Aaron,

A couple of things here. The first is that I'm sure you know the names of your routes, but when I spin up a new workspace the default route name for the kb page is actually 'kb' rather than 'kb_view' so I would double check that to make sure.

The bigger issue is that it appears there may be a defect in San Diego around scripting the link to destination event handler where it doesn't work while using the form view does work. There is a workaround, which is to run a cache.do on your instance. I was able to replicate both this error (using your script with kb instead of kb_view) and then it worked after I cleared the cache on that instance.

Just a quick disclaimer that clearing the cache is something you want to be careful about, especially in production instances as the instance will run a little slower for a bit.

Community Alums
Not applicable

Thanks Brad, that did it.   

The route is 'kb_view'  this is a demo instance that's been upgraded for about 4 releases, so perhaps that's new change in San Diego.

It appears that you have to do a cache.do  after each modification/save of the script as well.   Anything I should do to submit this defect?

I also modified targetRoute: 'current'   to open in sub tab and it's working great.

Thanks,

Aaron