Is there a way, or what's the best practice of pre...
# suitescript
b
Is there a way, or what's the best practice of preventing a user from using the back button to go back to the previous page in a Suitelet? My use case is that I'm rendering a list (batch) of orders to be printed for the fulfillment team. Upon them clicking the "process batch" button, the suitelet creates a MR task to update these order lines as needed with a batch ID and then renders the list as a pdf in the current window. My issue is that I don't want people to click the back button which takes them back to list and reclick the submit button, re-initiating the MR process. I could have the pdf auto download and then redirect in the current window with window.replace() but that is not as efficient since a user has to open the pdf file to print it rather than printing from the dialog in the window.
r
I have hack... maybe a way, but not best practice….sorry @battk, but still learning. waited to see if you or someone else answered. you could have suitlet 1 call suitlet 2 who sets session variable as ‘last_called_timestamp’. Have suitelet 2 be an intermediary that executed the actual functionality. It they back button then have suitelet 1 check ‘last called timestamp’ and tell user to wait 20 min. this is what some websites do that are not nice. They redirect you to an middle man web site that when you back button it redirects you back forward. Some forward the request 5-6 times but you dont always see it. some manipulate the history function of the browser. its not clean but a session variable has been done before outside of NS
b
good to know, thanks @redfishdev. Of course the simplest and best option is user training, but rarely is that ever enough. I think I'll trying something with window.unload or better yet, perhaps I can have a NS dialog window open telling users the batch has processed and not to click the back button. I think this is more of an edge case but i can see it happening. if any one has any other suggestions, I'm open to it. another option i was considering is if it's possible to open yet another window and render the PDFs in that one and then send the one where the submit button was clicked to a "processed" page, but I can't figure out how to send a post request when writing the server side html for it. but perhaps this is an instance where i need to look into one suitelet calling another.
b
probably easier to just open the pdf in a new tab
will involve making your code work for a get instead of a post
b
okay, thanks, that's what I thought and was considering as well, but I'm stuck on how to pass the order information via GET
b
query parameter is the usual choice
b
right, but aren't there character limitations there? or is it different than url parameter?
I suppose I could save the file that's rendered and use the query param to send an id and then in the GET request, load that file and then delete it so as not to inflate our storage
b
there are, though its unlikely you hit them
b
is the query param different than a url param? or are they the same. if they same, the limit is 2048 characters and I'd hit that in a hurry if i passed order information through.
thanks for the help!!!
b
same thing
the query of the url is the part after the ?
b
okay, so i can't pass order info there, it'd have to be the reference to the file. but that i can do.
b
a file is not convenient to create from client side code
b
the file would be created by the suitelet server side, correct?
b
usually these sort of things have users selecting which orders they want to process
which happens clientside
they submit a list, and in this case, it sounds like you render a pdf and mark the orders as processed
b
ah, yeah. so basic flow is suitelet opens window asking user to select location, they do and upon field change the suitelet renders the list for them and they can then click process.
you nailed it
currently, they don't have the option to choose what orders to print, but that may come later.
b
rendering a file means you dont actually return html, so you cant open a new window for your pdf
you dont have a way of creating a file to use later without adding another step in between
b
doesn't renderAsPdf return a File object that I could save though?
b
its your pdf, but it sounds like you want to pass your orders in a file
which you cant create client side
b
oh, no, sorry, i could create the PDF of orders and just load that in the GET.
create PDF of orders in POST, then pass query param of file id to GET to render to user in new window. that was my thought.
if i'm way off base, i apologize, this is my first suitelet
b
basics are to use window.open to do a get to your suitelet
that way there is no back option, you never left the original page
b
makes sense.
thanks for everything!