The CreatorCon Call for Content is officially open! Get started here.

Redirect users in native UI using onSubmit client script

Community Alums
Not applicable

Hi All,

I have a form link on work order task form which opens a catalog item. I have a onSubmit client script to redirect user to a list of records after submitting this catalog item in native UI. Below is the script:

top.window.location = redirect_url;

I have als tried window.open(redirect_url, "_top");

This works fine if its opened in the main window. But if I open task in a new tab, the redirect doesn't work. Any ideas on how to make it work even when link is opened in new tab?

1 REPLY 1

Tushar
Kilo Sage
Kilo Sage

Hi @Community Alums 

 

something like this should help - 

var redirect_url = 'https://www.example.com/list_of_records';

function onSubmit() {
    // Check if the current window is opened by another window
    if (window.opener && !window.opener.closed) {
        // Redirect the opening window
        window.opener.location.href = redirect_url;
        // Close the current window
        window.close();
    } else {
        // If not opened by another window, redirect in the current window
        window.location.href = redirect_url;
    }
}

 


Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar