Diff (Table and Table)
Confirms the difference between two Table-type Data Items line by line
2018 © Questetra, Inc. (MIT License)
Configs
  • A: Select TABLE DATA for Original *
  • B: Select TABLE DATA for New *
  • C: Select STRING DATA for Difference (update) *
Script
//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving ==
const dataIdA = configs.get( "conf_DataIdA" ) + "";
const dataIdB = configs.get( "conf_DataIdB" ) + "";
const dataIdC = configs.get( "conf_DataIdC" ) + "";

//// == Data Retrieving ==
const myAtable = engine.findDataByNumber( dataIdA );
const myBtable = engine.findDataByNumber( dataIdB );
// com.questetra.bpms.core.model.formdata.ListArray (BPMS Table)
if( myAtable === null){
  throw new Error( "Source Table data A is NULL" );
}
if( myBtable === null){
  throw new Error( "Source Table data B is NULL" );
}
const myAtableSize = myAtable.size() - 0;
const myBtableSize = myBtable.size() - 0;
engine.log( "Original A: " + myAtableSize );
engine.log( "New Data B: " + myBtableSize );


//// == Calculating ==
let myAarr = [];
for (let i=0; i < myAtableSize; i++){
  let tmpRow = "";
  for (let j=0; j < myAtable.getRow(i).size(); j++){
  // com.questetra.bpms.core.model.formdata.ListArray.ListRow
    tmpRow += myAtable.get(i, j);
    if( j !== myAtable.getRow(i).size() - 1 ){ tmpRow += "\t"; }
  }
  myAarr.push( tmpRow );
}

let myBarr = [];
for (let i=0; i < myBtableSize; i++){
  let tmpRow = "";
  for (let j=0; j < myBtable.getRow(i).size(); j++){
  // com.questetra.bpms.core.model.formdata.ListArray.ListRow
    tmpRow += myBtable.get(i, j);
    if( j !== myBtable.getRow(i).size() - 1 ){ tmpRow += "\t"; }
  }
  myBarr.push( tmpRow );
}

let tmpAdd = "";
for (let i=0; i < myBarr.length; i++){
  let existFlag = false;
  for (let j=0; j < myAarr.length; j++){
    if( myBarr[i] === myAarr[j] ){
      existFlag = true;
      break;
    }
  }
  if( existFlag === false ){
    tmpAdd += "+" + i + " " + myBarr[i] + "\n";
  }
}

let tmpDel = "";
for (let i=0; i < myAarr.length; i++){
  let existFlag = false;
  for (let j=0; j < myBarr.length; j++){
    if( myAarr[i] === myBarr[j] ){
      existFlag = true;
      break;
    }
  }
  if( existFlag === false ){
    tmpDel += "-" + i + " " + myAarr[i] + "\n";
  }
}


//// == Data Updating ==
engine.setDataByNumber( dataIdC, tmpAdd + tmpDel );

} //////// END "main()" ////////

Download

Capture

Notes

  • Example of output when one line has been added in line 10: “+10 Questetra”

1 thought on “Diff (Table and Table)”

  1. Pingback: Help: Table-Type – Questetra Support

Comments are closed.

%d bloggers like this: