Team, for a client script, is there a way to do so...
# suitescript
a
Team, for a client script, is there a way to do something similar to an ajax call? What I am trying to resolve is this. The user can add a file into a custom field on Invoices. We need to restrict the type of document to only PDFs. On the client script, we get on that custom field the file id. To validate the type, I would have to use the N/file module to load the file and check the type (which only works on server side). Any ideas on how to do this? We want to do this as soon as the user adds the file, and not later on when saving the record.
m
i have done things like this in the past, if i'm not wrong i did it using jquery on the client script once you detect the event to upload send the request to a suitelet host the file and wait the the promise in the client to modify the view
b
you can probably get away with simply using CurrentRecord.getText on the field to get the filename
c
I would think a simple http fetch call would work?
a
with getText and base it on the file extension?
thanks Martin, the jQuery idea would be good
c
Make a restlet or suitelet, use HTTP fetch to make a call as part of the field changed validation, passing the file ID to the restlet/suitelet. On the server side use N/file module as needed, and return whatever data you want'
a
nice
I will try that
c
getText could work as martin said if you’re find with relying on the file name. No ajax call needed
a
ok
with the HTTP module I don't need jQuery, right? I can just do it in the fieldChanged entry point. right?
c
Yeah you can use the http module as well instead of fetch
N/http
a
ok, thanks
c
http.get(“PATH TO YOUR SUITELET/FILEID”) — SOmething like that
a
cool
That worked perfect, created a SL to validate the file type, responding true or false. I call the SuiteLet from the fieldChanged event passing the fileId
Thanks a lot guys!!
you rock
z
@Antonio Garcia you asked for AJAX... yes you can do that with suitelet, but RESTLET is right choice.
a
hi, thanks, yes, that's probably better... Would the Restlet need authentication when called internally?