Questetra BPMS: Process, Concat All Strings

Questetra BPMS: Process, Concat All Strings

Concatenates all string type data. Searches and joins string data and title strings stored as workflow data of Questetra BPM Suite. A line break is added between each data. It is used for checking the existence of keywords.

2019-11-05 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/questetra-bpms-process-concat-all-strings/

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: Select STRING DATA for Concatenated String (update)
  • E: Select STRING DATA for Concatenated String (new lines added)
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)


//////// 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 dataIdD         = configs.get( "conf_DataIdD" )   + "";  // not required
const dataIdE         = configs.get( "conf_DataIdE" )   + "";  // 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 );


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

//// == 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 );

// retrieve JSON
let concatenatedText = "";
    concatenatedText += responseObj.processInstance.processInstanceTitle + "\n";
for( const key in responseObj.processInstance.data ){
  if( responseObj.processInstance.data.hasOwnProperty(key) ) {
    engine.log( key + ": " + responseObj.processInstance.data[key].dataType );
    if( responseObj.processInstance.data[key].dataType === "STRING" ){
      if( responseObj.processInstance.data[key].value == null ){
        engine.log( " AutomatedTask Json: null string" );
      }else{
        concatenatedText += responseObj.processInstance.data[key].value + "\n";
      }
    }
  }
}
concatenatedText = concatenatedText.replace(/[\n]*$/, "");


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


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

Download

Capture

Concatenates all string type data. Searches and joins string data and title strings stored as workflow data of Questetra BPM Suite. A line break is added between each data. It is used for checking the existence of keywords.

Notes

  1. It can also be used for data items for full text search
  2. It supports loop processing
  3. It does not support Discussion type or Table type

See also

Leave a Reply

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

%d bloggers like this: