This topic contains 6 replies, has 0 voices, and was last updated by qpongrass 6 years, 9 months ago.
-
AuthorPosts
-
January 30, 2018 at 11:13 am #21297
qpongrassIs it possible to use a standard html input type=file on an external suitelet and retrieve the file on the post action either via request.getFile or some other method? The NetSuite form.addField makes it impossible to customize the position, color, size, etc. of the file field.
This is a cached copy. Click here to see the original post. -
January 31, 2018 at 11:42 am #21298
JohnCColeI've done something like what your asking. I have a node.js application uploading a file to a suitelet. As long as the enctype on the form is multipart/form-data, and the name and id of the form file field is 'file', I can access that file in the suitelet using getFile.
-
February 5, 2018 at 6:20 am #21299
qpongrassJohnCCole, how did you get it to work? Could you provide some code samples? I tried using the following code, but the file object is always null on the form post.
On Get:
html += '<form action="/app/site/hosting/scriptlet.nl?script=377&deploy=1" method="post" enctype="multipart/form-data">'
html += 'First name: <input type="text" name="fname"><br>'
html += '<input type="file" name="nsfile" id="nsfile"><br>'
html += '<input type="submit" value="Submit">'
html += '</form>'
form.addField('html', 'inlinehtml', null,null,null).setDefaultValue(html);
response.writePage(form);
On post:
var file = request.getFile("nsfile")
-
February 5, 2018 at 3:03 pm #21300
JohnCColeNot sure if it's a un-intended feature but it appears if you write the response with write method instead of writePage it will work.
If you use an NSForm object and then call writePage it appears an actual file field has to be added to the form (not raw html) for things to work, but then you're back to not being able to perhaps position the NetSuite field the way you want.
I'm assuming you don't want to be without the NS API that comes with a form when doing a writePage so what kind of styling/positioning are you trying to do with the file field?
-
February 8, 2018 at 6:01 am #21301
qpongrassGenius. Thank you. This alleviates one of my biggest headaches.
Here is the code on the GET:
html += '<form action="/app/site/hosting/scriptlet.nl?script=377&deploy=1" method="post" enctype="multipart/form-data">'
html += 'First name: <input type="text" name="fname"><br>'
html += '<input type="file" name="nsfile" id="nsfile"><br>'
html += '<input type="submit" value="Submit">'
html += '</form>'
response.write(html);
POST can use the NS API as normal:
var file = request.getFile("nsfile")
file.setFolder(981194)
var id = nlapiSubmitFile(file)
-
February 9, 2018 at 8:26 am #21302
JohnCColeNot a problem. As long as you don't need the SuiteScript API on the client side it does the trick.
-
February 9, 2018 at 8:39 am #21303
qpongrassCorrect. This really solved a long-standing deficiency in my understanding.
-
AuthorPosts
You must be logged in to reply to this topic.