Using a ClientScript function, how can I redirect ...
# suitescript
d
Using a ClientScript function, how can I redirect a user to another page? Simple use case would be like a “Home” button that would send the user…. to.. https://######.app.netsuite.com/app/center/card.nl
s
you can use the URL module to resolve the path to the record
s
in a client script, I just use the native browser functionality
d
window.location = <url> seems like a better fit
thanks… I thought there must be some complicated NetSuitian way to do it
s
Yep, and for parsing parameters, this is a fantastic option: https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams
parsing, setting, clearing...
m
window.location = window.location.origin + '/app/center/card.nl';
EDIT: See my comment further below for a better solution.
d
@Michael Pope Nice… and clean.
m
@David Durst Thanks 🙂 Yeah... had to do this a few times before and I want as little breakage as possible... I'm sure there's a better way but this is what I use.
d
would be nice if there was some form of API for Centers & Menu’s
Django and JavaServerFaces has named URL structures…. that way it would future proof any URL structure changes NS might make
m
I think there might be, but I've never gotten it to work well. IN SS 1, it's nlapiResolveURL(). However, I'm not sure it can redirect to the homepage... guess I'll have to try.
@David Durst Got it working. Here you go
window.location.origin + nlapiResolveURL('tasklink', 'CARD_-29');
That should work for any SS 1.0 setting regardless of changes in the URL of the homepage.
If you lookup 'tasklinks' in the Help section in Netsuite, it can show you how to do it (though it's a bit obscure the way they hide the info =0)
SS2 example would use url.resolveTaskLink