UIB Link to destination

Dimitar Vutov
Tera Contributor

Hello,
I'm looking for a way to script a "link to destination" action(in a list component), so that it points to a page in our service-now instance, but is not part of the "experience". The current problems I'm facing are:
- I cannot point to an external url when using a scripted handler. Instead I get a "Page doesn't exist".

- I cannot access the current instance name inside the script, so that I can build the proper url. I tried using the window object, but it is not defined even though that the script seems to be executed on the client, since my console.log works.
The reason I'm using a script is that we need to create a dynamic url, but don't want to use an "experience" page.

Example code:

/**
 * @Param {params} params
 * @Param {api} params.api
 * @Param {any} params.event
 */
function evaluateEvent({
    api,
    event
}) {
    if (event.payload.table && event.payload.table === 'incident') {
        return {
            route: `https://www.google.com`,
            fields: null,
            params: null,
            redirect: null,
            passiveNavigation: null,
            title: null,
            multiInstField: null,
            targetRoute: null,
            external: true,
            navigationOptions: null
        };
    }
    return {
        route: null,
        fields: null,
        params: null,
        redirect: null,
        passiveNavigation: null,
        title: null,
        multiInstField: null,
        targetRoute: null,
        external: null,
        navigationOptions: null
    };
}

 Instance version: Vancouver

5 REPLIES 5

Subhashis Ratna
Tera Guru

Hi @Dimitar Vutov ,

Could you please go through this article? I hope it will help you.
Link : https://www.servicenow.com/community/developer-forum/get-instance-url-via-ui-builder/m-p/2735950/pag...

Please mark my answer helpful and correct.

 

Regards,

Subhashis

 

Hi! Thank you for you answer, I totally overlooked the data resources as a means to 'deliver' the instance name. Thank you! However this only solves half of my issue, since I still have to redirect dynamically outside of the "experience" and currently I can't do that with a scripted action handler. Any ideas are welcome!

NicoD1
Tera Contributor

Hello Dimitar,

 

this might be a very late response but I had a similar requirement as you recently and this is the solution I found.

 

/**
 * @Param {params} params
 * @Param {api} params.api
 * @Param {any} params.event
 */
function evaluateEvent({
    api,
    event
}) {

    const payload = event.payload;
    const sys_id = payload.row.sys_id.value;
    const table = payload.table;

    return {
        route: null,
        fields: null,
        params: null,
        redirect: null,
        passiveNavigation: null,
        title: null,
        multiInstField: null,
        targetRoute: null,
        external: {
            url: "/now/nav/ui/classic/params/target/" + table + ".do%3Fsys_id%3D" + sys_id
        }
    };
}

 this code lets you open a record in platform view from a workspace list component (instead of opening another tab in the workspace).

 

I've found that it's not necessary to specify the instance name in the url section as it wil insert it automatically (in my case at least).

 

Hope this helps!

THIS IS WHAT I'VE BEEN LOOKING FOR!!!! THANK YOU NicoD1!!! Is there documentation anywhere to explain this return object? I'd love to be able to manipulate it more in the future