// 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 urlTextSource = 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 urlText = "";
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 === "FILE2" ){
if( responseObj.processInstance.data[key].value == null ){
engine.log( " AutomatedTask Json: FILE not attached" );
}else{
engine.log( " AutomatedTask Json: #FILE " +
responseObj.processInstance.data[key].value.length );
for(let i = 0; i < responseObj.processInstance.data[key].value.length; i++ ){
urlText += applicationRoot + "PE/Workitem/File/download?id=" +
responseObj.processInstance.data[key].value[i].id +
"&processDataInstanceId=" +
responseObj.processInstance.data[key].value[i].processDataInstanceId + "\n";
}
}
}
}
}
urlText = urlText.replace(/[\n]*$/, "");
//// == Data Updating / ワークフローデータへの代入 ==
if( urlText === "" ){
engine.log( " AutomatedTask DataUpdating: FILE DATA not found" );
}
if( dataIdD !== "" ){
engine.setDataByNumber( dataIdD, urlText );
}
if( dataIdE !== "" ){
if( urlTextSource !== null ){
engine.setDataByNumber( dataIdE, urlTextSource + "\n" + urlText );
}else{
engine.setDataByNumber( dataIdE, urlText );
}
}
} //////// END "main()" ////////
Pingback: Questetra BPMS: Process, Concat All Strings – Questetra Support