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

Ankur Bawiskar
Tera Patron
Tera Patron

@pranay_14 

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.

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

Yes I checked , but couldn't find any anything .

@pranay_14 

please check below response.

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

Ankur Bawiskar
Tera Patron
Tera Patron

@pranay_14 

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

action.setRedirectURL(object)

AnkurBawiskar_0-1743762332094.png

 

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