NetSuite SuiteScript to modify file in the file cabinet

和自甴很熟 提交于 2019-12-24 03:19:07

问题


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:

  1. Load The File
  2. Create a file handle with:
    • Set the file name to one that you intended.
    • Set the content to intended one
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!