Questetra BPMS: Process, List All File URLs
Lists the download URLs for the files stored as workflow data in Questetra BPM Suite. If two or more files are attached multiple lines of text will be output. This can be used for browser extensions or pasted into the body of an email.
Configs
A: Select HTTP_Authz Setting *
B: Set WF Platform URL (${var[applicationRoot]} or https: //../) * #{EL}
C: Set Process ID ( e.g., “123” ) * #{EL}
D: Select STRING DATA for URL List (update)
E: Select STRING DATA for URL List (new lines added)
Script (click to open)
// GraalJS Script (engine type: 2)
// 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 strAuthzSetting = configs.get( "AuthzConfA" ); // required
engine.log( " AutomatedTask Config: Authz Setting: " + strAuthzSetting );
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 / 演算 ==
// get ProcessInstance via Questetra Workflow API
// com.questetra.bpms.core.event.scripttask.HttpClientWrapper
let apiRequest = httpClient.begin(); // HttpRequestWrapper
apiRequest = apiRequest.authSetting( strAuthzSetting ); // with "Authorization: Bearer XX"
// https://questetra.zendesk.com/hc/en-us/articles/360024574471-R2300#HttpRequestWrapper
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()" ////////
Download
2021-07-02 (C) Questetra, Inc. (MIT License)https://support.questetra.com/addons/questetra-bpms-process-list-all-file-urls-2021/ The Add-on import feature is available with Professional edition.
Notes
Use with Update Data and Multiline String, Get Specific Line etc.
Capture
See also
Like this: Like Loading...
Related