How to pass a parameter to an link to destination event in UI Builder?

Cory B
Kilo Expert

I want to create an event on a page so that when a row is clicked it goes to another page (outside of my application). So Im using the "link to destination" event handler and selecting type "external URL". However, I need to pass a parameter into this URL.  So I tried concatenating the url with data binding but that did not work, it looked something like this:

https://service-now.com/$flow-designer.do?sysparm_nostack=true#/operations/context/@payload.sys_id

find_real_file.png

 

Does anybody know how you can go about achieving this?  The source of the parameter would be one of the fields from the list.  You can notice Im trying to create this event under "row clicked"

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Unfortunately, you can't combine a string and value with the data binding, but I was able to make this work using the following steps:

In the Link to destination event handler, change the Mode from form to Script.

find_real_file.png

Use the following in the script box:

/**
* @param {params} params
* @param {api} params.api
* @param {any} params.event
* @param {any} params.imports
*/
function evaluateEvent({api, event}) {
	return {
		route: null,
		fields: null,
		params: null,
		redirect: null,
		passiveNavigation: null,
		title: null,
		multiInstField: null,
		targetRoute: null,
		external: {
			url:  "$flow-designer.do?sysparm_nostack=true#/operations/context/" + event.payload.sys_id
		}
	};
}

After clicking Apply and saving, when you test you should now get that URL opened in a new tab when clicking on the list.

View solution in original post

10 REPLIES 10

Hi David, this is currently undocumented, unfortunately. I had to go hunting internally to find an example.

How can I do this with without opening in a new tab? In the Operation Succeeded event of my 'create' data source I want to redirect the user to the newly created record (getting the sysid of the new record from the event payload). I've tried everything I can think of in setting route and params, but I always get The page you are looking for could not be found. I have not been able to find any documentation on setting these values.

Found it here: https://docs.servicenow.com/bundle/sandiego-application-development/page/app-store/dev_portal/API_reference/helpers/concept/helpersAPI.html

I'm not actually using helpers in this context (event handler) but the syntax seems to be the same.

Example redirect:

return {
        route: "service-request",
        fields: {
            "sysId": sysId
        },
        params: null,...

To anyone else who's been struggling with this: the fields are required params, the params are optional params.

I can't even begin to describe how thankful I am for you. CHEERS!

@Brad Tilton , you are amazing. This worked out for me too.

Great, Thanks!