In PHP we use fwrite() function to write a file, h...
# suitescript
m
In PHP we use fwrite() function to write a file, how we can do exactly the same thing in Netsuite , write in a file , that will write to a text file and then we can download and save the file?
m
this doc is relatd to uploading files to filecabinet I want to upload and write file make changes add some text and when script run , it will save and can download
c
write the file to where ?
You can create new files using N/file and append to them. Then serve them from the file cabinet
Would probably help if you gave some context on what you're trying to do
The NS file cabinet is equivalent to a filesystem that'd be exposed to your PHP process on a web server. N/file is the only API that is exposed for you to use to manipulate file cabinet files (for good reason). Your other option, depending on what you want to do, is to just work in memory
m
ok fine, this is teh page i created which uploads the file and store in the file cabinet
and this is the code /** *@NApiVersion 2.x *@NScriptType Suitelet */ // possible option is to create a Suitelet with a Document field and save the // file uploaded to that field. Here's the code for such a Suitelet: define(['N/ui/serverWidget'], function(serverWidget) { function onRequest(context) { if (context.request.method === 'GET') { // creating form var form = serverWidget.createForm({ title: 'Form to write file' }); // add field var field = form.addField({ id: 'custpage_file', type: 'file', label: 'Document' }); form.addSubmitButton({ label: 'Submit Button' }); context.response.writePage(form); } else { var fileObj = context.request.files.custpage_file; fileObj.folder = 293909; //replace with own folder ID var id = fileObj.save(); } } return { onRequest: onRequest }; });