How to define priorities (order) of handlers in UI Builder component's event ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-26-2022 08:04 AM
Hi,
I added 2 event handlers to "Click button" event in UI builder - the first handler should create new record by script, the second one is "link to destination" and it should open external URL, where parameter is "sys_id" of newly created record. But during run time the "link to destination" handler is invoked first always (tested by debugger). How is possible to manage the order of execution ? Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2022 02:23 AM
Can you share the script on the first event? It should be possible to redirect directly instead of via a second event.
If my answer helped you in any way, please then mark it as helpful.
Mark
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-28-2022 06:07 AM
Hi Mark,
The following is my script :
............
I need to redirect to (full link with parameter) :

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-27-2025 04:39 AM
Hi did you resolved this? I encountered the same issue. In my case i have 2 events, one is calling a client script and the other is setting a form field value. however there is some delay on the setting form field value, its getting the previous value not the latest one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-27-2025 04:46 AM
Hi @ALEXANDER LYUBA
when multiple event handlers are attached to the same event, the order of execution isn't guaranteed unless explicitly controlled.
Create a single event handler that performs both actionsācreating the record via the API and then navigating to the desired URL after receiving the sys_id
.
function handler({ api, helpers }) {
debugger;
// Make the POST request to create the record
helpers
.snHttp("/api/now/table/x_728919_productor_logical", {
method: "POST",
body: {
lagname: api.state.lagSys_id,
},
})
.then(({ response }) => {
// Extract the sys_id from the response
const logicalSysId = response.result.sys_id;
api.setState('logicalSys_id', logicalSysId);
console.log("Sys_id = " + logicalSysId);
// Redirect to the external URL
const url = `https://dev117836.service-now.com/x_728919_productor_logical.do?sys_id=${logicalSysId}&sys_is_list=t...`;
// Use window.location.href for redirection
window.location.href = url;
})
.catch(({ error }) => {
// Handle errors
console.error("Error creating record:", error);
});
}
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ļ YouTube: https://www.youtube.com/@learnservicenowwithravi
ļ LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/