action.setRedirectURL(newUrl) is not working in server side declarative action.

pranay_14
ServiceNow Employee
ServiceNow Employee

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;
    }

}

 

7 REPLIES 7

@pranay_14 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

pranay_14
ServiceNow Employee
ServiceNow Employee

@Ankur Bawiskar I know action.setRedirectURL(object) takes the glide object, its not accepting the URL .

@pranay_14 

I think action.setRedirectURL() has some limitations when it comes to workspace.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader