办公文件柜十大名牌:重置文件柜中 CSV文件的内容(clear file cabinet)

我正在阅读用户的文件柜中的 CSV 文件的内容事件 Suitelet 生活在销售订单上,并在完成后尝试将文件的内容重置为空 CSV

我可以成功地追加行并读取内容,但没有关于重置 NetSuite 文档中的内容。我只是在寻找一种将文件重置为空 CSV 的方法。

/**
 *
  @NApiVersion 2.x
  @NModuleScope SameAccount
  @NScriptType UserEventScript
  @appliedtorecord salesorder
 */
define(['N/file'], function(file) {
  function resetCSVFile(context) {
    var fileObj = file.load({ id: '104819' });
    var iterator = fileObj.lines.iterator();
    var idArrays = [];
    iterator.each(function(line) {
      idArrays.push(line.value);
      // the line below is my failed attempt at resetting the line
      line.value = ''
      return true;
    });
    log.audit({ title: 'idArrays', details: idArrays });
    fileObj.save();
    return true;
  }
  return {
    afterSubmit: resetCSVFile
  };
});
1

处理完文件后,您将需要使用file.create()创建一个具有相同namefileTypefolder属性值的新文件对象。将该文件对象的contents属性设置为某个值(可能是标题行),然后保存它。这将用一个空文件覆盖现有文件,但

的示例捕获 CSV 文件的标题行,并使用该标题行创建一个空文件。创建文件对象时,contents 属性不能为 null 或空字符串。

var fileObj = file.load({ id: '5447' });
var currentLine = 0;
var headerRow = '';
fileObj.lines.iterator().each(function(line) {
  currentLine++;
  if (currentLine === 1) {
    headerRow = line.value + '\n';
  }
  log.debug({ title: 'header', details: line.value });
  return true;
});
var newFile = file.create({
  name: fileObj.name,
  fileType: file.Type.CSV,
  folder: fileObj.folder,
  contents: headerRow
});
newFile.save();

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(616)
Python矩阵怎么表示:C中的矩阵表示(matrix representation)
上一篇
免费ftp服务器地址:使用特定IP地址访问FTP服务器(how to connect to ftp server with ip
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(74条)