action.setRedirectURL(newUrl) is not working in server side declarative action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 02:32 AM
I am on the record page within the workspace and have added a button. When the button is clicked, I want to capture the current page URL.
Specifically, I need to extract the sysID
parameter from the URL:
URL Format:<Instance Id>/now/mfg/isa-equipment-model/params/sys-id/<sysID>/selected-tab-index/4/sub/record/<table-name>/<record-sysId>
Current Issue:
I am using the sysID in my logic to fetch the next record's sysID and its corresponding table name. I then update the URL with these values and attempt to redirect the user to the new URL. During debugging, the code populates the correct values, the URL is updated correctly, but the redirection doesn't take place.
Code Snippet Overview:
I've attached the relevant code where I'm updating the currentURL
. It appears to work as expected during debugging—values are correct, and the URL is updated properly. However, the actual redirection doesn't occur.
var isaSysIdsArr = [entitySysId];
// Step 2: Query devices in natural order
var deviceGr = new GlideRecord('TABLE_TO_BE_QUERIED');
deviceGr.addQuery('relci_parent', 'IN', isaSysIdsArr);
deviceGr.query();
while (deviceGr.next()) {
var deviceSysId = deviceGr.getValue('ci_sys_id');
var deviceClass = deviceGr.getValue('ci_sys_class_name');
if (deviceSysId == currentDeviceSysId) {
foundCurrent = true;
continue;
}
if (foundCurrent) {
var urlParts = currentUrl.split('/');
urlParts[urlParts.length - 1] = deviceSysId;
urlParts[13] = deviceClass;
var newUrl = urlParts.join('/');
action.setRedirectURL(newUrl);
break;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 03:18 AM
did you check in any existing OOB server side declarative action?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 03:28 AM
Yes I checked , but couldn't find any anything .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 03:33 AM
please check below response.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2025 03:25 AM
what comes in your newUrl?
are you sure it's a valid URL? Did you print it?
I could see lot of Server Side Declarative actions using this and it works fine there
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader