i do understand that, however uploading the file t...
# suitescript
m
i do understand that, however uploading the file to the file cabinet will take the same amount of time as uploading it to my desired destination. This would mean that uploading it to the file cabinet (synchronously) will block the page in the same manner?
v
Where is user uploading this file , on a suitelet screen ?
Or on a transaction record ?
m
at the moment directly on a (new) custom record page
v
And you want to save that file simultaneously to another destination ?
m
i'm building the following:
s
@Menno Janssen What are you trying to achieve ?
v
You can call an after submit user event script to pick the file id from the custom record , load it and send it to your desired destination (all server side)
m
custom record named 'onedrive file' this record can be attached as a child to a case record for example. when a user create a new onedrive file record i have an inline html drop area, in which you can drop the file. when clicking save the client-side script will upload to onedrive and receive details back from the OneDrive API. the Netsuite record is updated with this. this all works well when doing the PUT requests synchronously. however this blocks the UserInterface for a short while. Ideally i would like to show a progress bar which offcourse updated when there is progress. this means that i need to use async PUT calls. so that i can update the user interface, which is where my problem described earlier comes from.
v
Ok, in that case, add 2 fields: a hidden checkbox field & an inline html field(for your progress bar)
OnSave event start your async code and inside it update the checkbox to true
Also return true when checkbox is true or give a pop up - file save in progress - please wait
This way even if the script won't stop for your async method to complete , it wouldn't save the record and just ask user to wait
m
right, which would mean the user can press save again after it is done uploading. checkbox is true, this record will be saved
v
Also after completion since you'll be changing the icons of your inlinehtml field, user will know when to save it finally
Yep
Also you can run code inside async operation only when checkbox is false
m
alright, i like that method. but what do i do when a user cancels the record after the file is uploaded. can i run code on 'Cancel' event? else i would be stuck with an uploaded file with no related Netsuite record.
v
Hmm, you've lost me there my friend 🙂 (Have to think about that scenario )
There is no function on cancel
m
this is me all day today. Find solution for one issue, get presented with another. none of them fix all my problems😅
v
Well one way would be to use a checker on parent Case record
m
can you explain that one ?
v
Or create a custom log record for such failed cases, so on start of async(create a custom record having only 3 fields - process started, process finished, file id)- at the end of the day you can delete all the records for which process started but never finished
I'm assuming you're using an API to upload the file, which returns a file Id or UUID , right ?
m
correct, fileID is returned. so if i have that i can delete the file with the same API.
this would be some more effort but will keep me from manipulating the DOM tree directly which is not officially supported. I think i have my options on the table 👍
v
So a way to make this go full circle would be : in your async method (create a new status/logger custom record , process started: true, process finished: false, fileId: null ) --- On completion of your async and before returning true for onSave ( fill process finished: true, fileId: 1234 )
So any records with a fileId: num, process finished: false , would imply that this file needs to be deleted
All records where onSave was successfully used will have ( file started: true, process finished: true, fileId: num ) -- so you can simply clear them in Netsuite -- success cases
All records where ( file started: true, process finished: false, fileId: num ) -- delete them from external db -- cancelled cases
m
got it! seems like i got some work to do.. thanks a lot for all the help👍
v
No problem, I'm sure there could be a better fix if we sit and think through, but this is all I could come up with for now. 🙂