问题
We have files within the NetSuite file cabient which need to be updated (the url field has changed). I found the noted article on this site but there is no code example to perform the requested. It indicates to use the nlapiLoadFile and nlapiSubmitFile calls; would anyone be able to assist with a code example?
Link: Can Netsuite Suitescript modify a file in the file cabinet?
回答1:
Ya, it seems a bit odd. The only way I found is:
- Load The File
- Create a file handle with:
- Set the file name to one that you intended.
- Set the content to intended one
- Set the folder and submit.
I have attached a code snippet
var file = nlapiLoadFile(file_id); var content = file.getValue(); content = '...put your content...'; file = nlapiCreateFile(file.getName(), 'FILE TYPE', content); file.setFolder(required_folder_id); nlapiSubmitFile(file);
Hope this helps.
回答2:
There is no special API function to edit an existing file, you could take the details of the existing file and create a new file with the same details but changing the data field only and deleting the old file.
var start = function(request, response)
{
var fileId = "107524";//get the existing file id
var file = nlapiLoadFile(fileId);
var data = file.getValue();
var name = file.getName();
var folderId = file.getFolder();
var fileType = file.getType();
nlapiDeleteFile(fileId);//delete the older file
data += ",this is the appended data";//change the data
var newFile = nlapiCreateFile(name, fileType, data);//create a new file with the same details
newFile.setFolder(folderId);
nlapiSubmitFile(newFile);//submit it
}
回答3:
Do you mean file instead of field? If you use nlapiLoadFile(/path/file), you can then use getURL() to provide a link to that file.
回答4:
NetSuite does not have a edit file kind of an API. You will have to load the original file, modify the contents as per your needs and then submit that data by creating a new file with same file name and inside the same folder. This simply overrides the existing file.
Here's the code sample:
var original = nlapiLoadFile(FILE_ID_OR_FILE_PATH_IN_FILE_CABINET);
var originalContent = original.getValue(); //Return the value (base64 encoded for binary types) of the file
var updated = nlapiCreateFile(original.getName(), FILE_TYPE, UPDATED_FILE_CONTENTS);
updated.setFolder(original.getFolder());
nlapiSubmitFile(updated);
来源:https://stackoverflow.com/questions/12592408/netsuite-suitescript-to-modify-file-in-the-file-cabinet