Email a Excel-CSV (Table)
Excel-CSV Email Attachment (Table).
Configs
  • A: Select TABLE DATA *
  • B: Set THROW COL IDs (e.g. “0,1,5,3,6”) *
  • C: Select STRING DATA for To Address *
  • D: Select STRING DATA for To Name *
  • E: Select STRING DATA for Email Subject *
  • F: Set From Address (e.g. “noreply@example.com”) *
  • G: Set From Name (e.g. “Accounting News”) *
  • H: Set ReplyTo Address (e.g. “admin@example.com”) *
  • I: Set ReplyTo Name (e.g. “Accounting News admin”) *
  • J: Select STRING DATA for Email Body *
  • K: Select STRING DATA for Attachment File Name *
Script (click to open)
// Email Table as Excel-CSV (ver. 20160907)
// (c) 2016, Questetra, Inc. (the MIT License)

//// == 自動工程コンフィグの参照 / Config Retrieving ==
var dataIdA = configs.get( "conf_DataIdA" ); // (returns Number)
var colIds = configs.get( "conf_ColIds" ) + "";
var dataIdC = configs.get( "conf_DataIdC" ); // (returns Number)
var dataIdD = configs.get( "conf_DataIdD" ); // (returns Number)
var dataIdE = configs.get( "conf_DataIdE" ); // (returns Number)
var fromAddress = configs.get( "conf_FromAddress" );
var fromName = configs.get( "conf_FromName" );
var replyToAddress = configs.get( "conf_ReplyToAddress" );
var replyToName = configs.get( "conf_ReplyToName" );
var dataIdJ = configs.get( "conf_DataIdJ" ); // (returns Number)
var dataIdK = configs.get( "conf_DataIdK" ); // (returns Number)

//// == ワークフローデータの参照 / Data Retrieving ==
var myTable = data.get( dataIdA );
// myTable: com.questetra.bpms.core.model.formdata.ListArray
var toAddress = data.get( dataIdC ) + "";
var toName = data.get( dataIdD ) + "";
var subject = data.get( dataIdE ) + "";
var myBody = data.get( dataIdJ ) + "";
var myFileName = data.get( dataIdK ) + "";

//// == 演算 / Calculating ==
if( myTable !== null){
  var colIdArray = colIds.split(",");
  var numOfCols = colIdArray.length;
  var numOfRows = myTable.size() - 0; // 行(Tableの高さ)

  var myTsv = "";
  for( var i = 0; i < numOfRows; i++ ){
    for( var j = 0; j < numOfCols; j++ ){
      if( j != numOfCols - 1 ){
        myTsv += myTable.get(i, parseInt( colIdArray[j] ) ) + "\t";
      }else{
        myTsv += myTable.get(i, parseInt( colIdArray[j] ) ) + "\n";
      }
    }
  }

  emailService.begin()
    .addTo( toAddress, toName )
    .setFrom( fromAddress, fromName )
    .setReplyTo( replyToAddress, replyToName )
    .setSubject( subject )
    .setBody( myBody )
    .addAttachment( myFileName, 'text/tab-separated-values; charset=x-UTF-16LE-BOM', myTsv)
    .send();
}

Download

2020-10-20 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/email-sendexcelcsv/
The Addon-import feature is available with Professional or Enterprise edition.

Notes

  • “0,1,5,3,6” means changing the column order into “ID:0, ID:1, ID:5,ID:3, ID:6” before generating the CSV

Capture

%d bloggers like this: