Hi all, I'm trying to add a button on my customer ...
# suitescript
a
Hi all, I'm trying to add a button on my customer form which when clicked will redirect the user to a saved search. I'm getting lost in a sea of suitelets, client side, user side, redirects, and resolve scripts. What would be the recommended way to go about this?
b
use Window.location to navigate to a url of your choosing
a
And I can that in a user event script? How would I pass in a parameter to use in the saved search in the Suitelet?
Thanks, I'm pretty new to Suitelets
b
user events and suitelets are server side scripts
buttons are client side
while it is possible to redirect using a server side script
you wont be using a button to do it
a
So I would set the button in user side, then use window.location in the form.addButton functionName to call the Suitelet?
b
open up your browser console
set window.location to your favorite url
s
You can also use
nlOpenWindow(urlhere)
and put the url of the saved search in there.
b
that looks like that opens a new window, which is different from redirecting
but if you want to open a new window, a suitelet or user event that redirects to a saved search becomes viable
a
It can open in a new window. Sorry, I'm still a bit confused. Would I still be setting the button in a user event script?
s
Yeah i prefer to use a new window rather the redirect what the current page depending on why you want to direct them to the saved search
b
there are 2 ways to add buttons
s
usually, you add a function name to the button, then you tell the form which client script the function is on...
Copy code
form.addButton({
            id: 'custpage_save',
            label: 'Update Record',
            functionName: 'updateRec()'
        });
form.clientScriptModulePath = './Update_RecFn_CL'
b
one is to add a custom action to your customer form and use the form's custom code to add the function used by your button
the other is in a user event script's beforeLoad entry point, which is what @Sandii example is
a
So the way that I have it set up now is in the user event script, before load. So basically on click it will redirect to the client side script? And then how would I get to the search results from there?
s
also, the simplest way is to do something like this
Copy code
context.form.addButton({
            id: 'custpage_testbutton',
            label: 'Click Me',
            functionName: '(function(){return nlOpenWindow("/app/common/search/searchresults.nl?searchid=264")})()'
        });
if you know your search id
a
Yes, that worked. Thank you so much!
351 Views