kintone Batch Acquisition of Two Columns of Data
Stores the value of the field code of two columns of the specified kintone application in a Data Item, and stores its communication log in a String-type Data Item.
2016 © Questetra, Inc. (MIT License)
Configs
  • A: Set Sub-Domain (https://{subdomain}.kintone.com/) *
  • B: Set App-ID (/k/”3″/) *
  • C: Set Api-Token *
  • D: Select STRING/SELECT for a Field-Code of Choice IDs *
  • E: Select STRING/SELECT for a Field-Code of Labels *
  • F: Select STRING DATA for Choice IDs (update) *
  • G: Select STRING DATA for Labels (update) *
  • H: Select STRING DATA for Access Log (update)
Script
//// == 工程コンフィグの参照 / Config Retrieving ==
var subDomain = configs.get( "conf_SubDomain" );
var appId     = configs.get( "conf_AppId" );
var apiToken  = configs.get( "conf_ApiToken" );
var dataIdD = configs.get( "conf_DataIdD" ); // (returns Number)
var dataIdE = configs.get( "conf_DataIdE" ); // (returns Number)
var dataIdF = configs.get( "conf_DataIdF" ); // (returns Number)
var dataIdG = configs.get( "conf_DataIdG" ); // (returns Number)
var dataIdH = configs.get( "conf_DataIdH" ) + ""; // (returns Number)

//// == ワークフローデータの参照 / Data Retrieving ==
var fieldCodeI = "";
if( data.get( dataIdD ) instanceof java.util.ArrayList ){
  fieldCodeI = data.get( dataIdD ).get(0).getValue() + "";
}else if( data.get( dataIdD ) instanceof java.lang.String ){
  fieldCodeI = data.get( dataIdD ) + "";
}
var fieldCodeL = "";
if( data.get( dataIdE ) instanceof java.util.ArrayList ){
  fieldCodeL = data.get( dataIdE ).get(0).getValue() + "";
}else if( data.get( dataIdE ) instanceof java.lang.String ){
  fieldCodeL = data.get( dataIdE ) + "";
}

//// == 演算 / Calculating ==
var accessLog = "";
var responseJson = "";

var choiseIds = "";
var choiseLabels = "";

try{
  var uri = "https://";
  uri += subDomain;
  uri += ".cybozu.com/k/v1/records.json";

  var response = httpClient.begin()
    .header("X-Cybozu-API-Token", apiToken )
    .queryParam( "app", appId )
    .queryParam( "fields[0]", fieldCodeI )
    .queryParam( "fields[1]", fieldCodeL )
    .queryParam( "query", "order by " + fieldCodeI + " asc" )
    .get( uri ); 
  accessLog += "---GET request--- " + response.getStatusCode() + "\n";
  responseJson = response.getResponseAsString();
  if( response.getStatusCode() == 200 ){
    var jsonObj = JSON.parse( responseJson );
    for( var i = 0; i < jsonObj.records.length; i++ ){
      choiseIds += jsonObj.records[i][fieldCodeI].value + "\n";
      choiseLabels += jsonObj.records[i][fieldCodeL].value + "\n";
    }
  }
}catch(e){
  accessLog += e.message + "\n";
}
// for Debug
// accessLog += responseJson + "\n";

//// == ワークフローデータへの代入 / Data Updating ==
retVal.put( dataIdF, choiseIds );
retVal.put( dataIdG, choiseLabels );
if( dataIdH !== "" ){
  retVal.put( dataIdH, accessLog );
}

Download

Capture

Notes

  • You cannot specify fields which is an array-value or contains line-break code
  • Field Code for “Record Number” should be specified as “$id”
%d bloggers like this: