Questetra BPMS: Process, Extract as TSV

Questetra BPMS: Process, Extract as TSV

Extracts process data as single-line TSV string. Items are specified in CSV format such as “0,2,3”. Tab code and line feed code are automatically deleted. Discussion type, Table type, Guide-Panel type cannot be extracted (Warning Log).

2019-11-19 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/questetra-bpms-process-extract-as-tsv/

Configs
  • A: Select OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • B: Set WF Platform URL (${var[applicationRoot]} or https://../) * #{EL}
  • C: Set Process ID ( e.g., “123” ) * #{EL}
  • D: Set DataItem IDs to Extract ( e.g., “0,2,3” ) * #{EL}
  • E: Select STRING DATA for Extracted TSV (update)
  • F: Select STRING DATA for Extracted TSV (append)
Script
// about Questetra Workflow API
// See https://online-demo-ja.questetra.net/s/swagger/index.html?urls.primaryName=Workflow%20API
// or "https://{YOUR}.questetra.net/s/swagger/index.html"

// about Questetra OAuth2 (for System Admin)
// Get ID&Secret: System Settings > API Clients > OAuth2 Clients > Add OAuthw Client
// (config "Redirect URL" = "https://s.questetra.net/oauth2callback" )
// (Scope: "read" or "any" )
// Set ID&Secret: Workflow App > Detail > OAuth2 Setting > (Get Refresh Token)

// Notes:
// Tab code and line feed code in Workflow data will be deleted.
// Workflowデータ内のタブコードと改行コードは抽出時に削除されます
// Specify "Title" to extract Title and "Id" to extract ID. ( e.g. "Title,Id,0,2,3" )
// 案件タイトルの抽出には "Title" を、IDの抽出には "Id" を指定します ( 例 "Title,Id,0,2,3" )
// If an undefined dataitem ID or Guide Panel ID is specified, "#N/A" is output.
// 未定義のデータ項目IDやガイドパネルのIDが指定された場合は、"#N/A" が出力されます
// If an unsupported type is specified, "#TYPE!" is output.
// サポート外のデータ型が指定された場合は、"#TYPE!" が出力されます
// The file names are extracted for the File type. (Multiple: Space-separated)
// ファイル型を指定した場合、ファイル名が抽出されます(複数:スペース区切り)
// The display strings of the selected options are extracted for the Select type. (Multiple: Space-separated)
// 選択型を指定した場合、表示テキストが抽出されます(複数:スペース区切り)
// It supports loop processing.
// ループ処理に対応しています(抽出結果の追記)


//////// START "main()" ////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const oauth2          = configs.get( "conf_OAuth2"  )   + "";       // required
const applicationRoot = configs.get( "conf_ApplicationRoot" ) + ""; // required
const processId       = configs.get( "conf_ProcessId" ) + "";       // required
const dataitemIds     = configs.get( "conf_DataitemIds" ) + "";     // required
const dataIdE         = configs.get( "conf_DataIdE" )   + "";       // not required
const dataIdF         = configs.get( "conf_DataIdF" )   + "";       // not required
// 'java.lang.String' (String Obj) to javascript primitive 'string'

engine.log( " AutomatedTask Config: Application Root: " + applicationRoot );
engine.log( " AutomatedTask Config: Process ID: " + processId );
engine.log( " AutomatedTask Config: Dataitem IDs: " + dataitemIds );


//// == Data Retrieving / ワークフローデータの参照 ==
let strBeforeAppend = engine.findDataByNumber( dataIdF );


//// == Calculating / 演算 ==
// obtain Access Token
const token  = httpClient.getOAuth2Token( oauth2 );

// get ProcessInstance via Questetra Workflow API
// com.questetra.bpms.core.event.scripttask.HttpClientWrapper
let apiRequest = httpClient.begin(); // HttpRequestWrapper
    apiRequest = apiRequest.bearer( token );
    apiRequest = apiRequest.queryParam( "processInstanceId", processId );
const apiUri = applicationRoot + "API/OR/ProcessInstance/view";

// request to API
engine.log( " AutomatedTask Trying: GET " + apiUri );
const response = apiRequest.get( apiUri );
const responseCode = response.getStatusCode() + "";
engine.log( " AutomatedTask ApiResponse: Status " + responseCode );
if( responseCode !== "200"){
  throw new Error( "\n AutomatedTask UnexpectedResponseError: " +
         responseCode + "\n" + response.getResponseAsString() + "\n" );
}
const responseStr = response.getResponseAsString() + "";
const responseObj = JSON.parse( responseStr );
//engine.log( responseStr ); //test

// retrieve JSON
let strNewline = "";
let arrDataitemIds = dataitemIds.split(","); // e.g. "Title,Id,0,2,3"
for( let i = 0; i < arrDataitemIds.length; i++ ){
  if( arrDataitemIds[i] === "Id" ){
    strNewline += responseObj.processInstance.processInstanceId;
  }else if( arrDataitemIds[i] === "Title" ){
    if( responseObj.processInstance.processInstanceTitle !== null ){
      strNewline += responseObj.processInstance.processInstanceTitle;
    }
  }else{
    if( responseObj.processInstance.data[ arrDataitemIds[i] ] == undefined ){
      strNewline += "#N/A";
    }else if( responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "STRING" || 
              responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "DECIMAL" || 
              responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "DATE" || 
              responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "DATETIME" || 
              responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "QUSER" || 
              responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "QGROUP" ){
      if( responseObj.processInstance.data[ arrDataitemIds[i] ].value !== null ){
        strNewline += responseObj.processInstance.data[ arrDataitemIds[i] ].value
                      .replace( /\n/g, '' ).replace( /\t/g, '' );
      }
    }else if( responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "SELECT" ){
      if( responseObj.processInstance.data[ arrDataitemIds[i] ].value !== null ){
        for( let j = 0; j < responseObj.processInstance.data[ arrDataitemIds[i] ].value.length; j++ ){
          strNewline += responseObj.processInstance.data[ arrDataitemIds[i] ].value[j].display
                        .replace( /\n/g, '' ).replace( /\t/g, '' );
          if( j !== responseObj.processInstance.data[ arrDataitemIds[i] ].value.length - 1 ){
            strNewline += " "; // (Multiple: Space-separated)
          }
        }
      }
    }else if( responseObj.processInstance.data[ arrDataitemIds[i] ].dataType === "FILE2" ){
      if( responseObj.processInstance.data[ arrDataitemIds[i] ].value !== null ){
        for( let j = 0; j < responseObj.processInstance.data[ arrDataitemIds[i] ].value.length; j++ ){
          strNewline += responseObj.processInstance.data[ arrDataitemIds[i] ].value[j].name
                        .replace( /\n/g, '' ).replace( /\t/g, '' );
          if( j !== responseObj.processInstance.data[ arrDataitemIds[i] ].value.length - 1 ){
            strNewline += " "; // (Multiple: Space-separated)
          }
        }
      }
    }else{
      strNewline += "#TYPE!";
    }
  }
  if( i !== arrDataitemIds.length - 1 ){
    strNewline += "\t";
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
if( strNewline === "" ){
  engine.log( " AutomatedTask DataUpdating: Extracted Text empty" );
}
if( dataIdE !== "" ){ 
  engine.setDataByNumber( dataIdE, strNewline );
}
if( dataIdF !== "" ){ 
  if( strBeforeAppend !== null ){
    engine.setDataByNumber( dataIdF, strBeforeAppend + "\n" + strNewline );
  }else{
    engine.setDataByNumber( dataIdF, strNewline );
  }
}


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

Download

Capture

Extracts process data as single-line TSV string. Items are specified in CSV format such as "0,2,3". Tab code and line feed code are automatically deleted. Discussion type, Table type, Guide-Panel type cannot be extracted (Warning Log).

Notes

  1. Tab code and line feed code in Workflow data will be deleted.
  2. Specify “Title” to extract Title and “Id” to extract ID. ( e.g. “Title,Id,0,2,3” )
  3. If an undefined dataitem ID or Guide Panel ID is specified, “#N/A” is output.
  4. If an unsupported type is specified, “#TYPE!” is output.
  5. The file names are extracted for the File type. (Multiple: Space-separated)
  6. The display strings of the selected options are extracted for the Select type. (Multiple: Space-separated)
  7. It supports loop processing.

See also

1 thought on “Questetra BPMS: Process, Extract as TSV”

  1. Pingback: Questetra BPMS: Process, Batch Extract as TSV – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: