I am using the N/file module to create and store f...
# suitescript
m
I am using the N/file module to create and store files in the file cabinet, but the problem I am facing is related to entry points, what should be the entry point for writing a file? I am using the define method and uploading the script in Netsuite.
n
What script type?
m
@NElliott I mean @NScriptType because there are 4 types of n script types, for example userevent, scheduled scripts, restlet scripts, etc. Which script would be used in my case?
n
Entirely depends on what you're trying to do...
There's no one type fits all.
It sounds like you need to understand the differences between the different script types.
m
I knew all diiferent types, I just want to create a file and store in the filecabinet
n
The N/File module will work with UE, SS, MR, SL. It depends on your user case and what you are trying to achieve.
n
You need to provide more context. For instance, are you wanting to create and save a file when a record is created? When data is posted to NS? When a SuiteLet has been submitted etc etc etc
m
I want to make button and when I click on the button a new file should create in the specified folder
@NApiVersion 2.0 @NScriptType UserEventScript define(['N/file'], function(file) { return{ beforeSubmit: customFunction } function customFunction() { // Create a file containing text var fileObj = file.create({ name: 'testHelloWorld.txt', fileType: file.Type.PLAINTEXT, contents: 'Hello World\nHello World' }); // Set the folder for the file fileObj.folder = 293909; // Save the file var id = fileObj.save(); // Load the same file to ensure it was saved correctly fileObj = file.load({ id: id }); } });
n
You need to understand the differences between the script types, that's not going to work. (or at least it will create a file every time in beoreSubmit) You will need to add a button with the UE script. The button will reference a client script function. Ideally the client script will create the file, but, I don't think n/file is available in client script. So you'll probably need your client script call a Suitelet to create your file for you.
d
^^ correct, the N/file module is only available server side
m
I have used Scheduled Script and execute the script in the testing mode and it has created the file in the file cabinet successfully.
n
Yes, if you're is accessing the record you have that UE script against that will do that... every time, and when a user opens the record and saves it.
m
actually I am finding the simple way to just create the file , just like we create and manipulate file in PHP using fwrite function, but obviously NS has its own coding style we need to follow all that SOP's , we can't just randomly code
btw brother @NElliott thanks alot for time and help
👍 1
j
If you want it to happen off a button, maybe a Custom Workflow Script.