Quser, Set One User of Qorg Randomly
Quser, Set One User of Qorg Randomly
Extracts one user from the members of Qorg randomly and sets that user in the Quser data. It is also possible to exclude specific users from the extraction target. If there are no candidates in the population, an error will occur.
Configs
  • A: Select QORG DATA *
  • B: If to be excluded, Set in each line (eg “a@example.com”)#{EL}
  • C: Select QUSER DATA that stores Extracted QUSER (update) *
Script (click to open)
// GraalJS Script (engine type: 2)

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

//// == Config Retrieving / 工程コンフィグの参照 ==
const qorgPocketPopulation = configs.getObject( "SelectConfA" ); /// REQUIRED ///////////
const strExcludedMembers   = configs.get( "StrConfB" );          // not required ////////
const quserPocketSelected  = configs.getObject( "SelectConfC" ); /// REQUIRED ///////////


//// == Data Retrieving / ワークフローデータの参照 ==
const qorgPopulation       = engine.findData( qorgPocketPopulation );
  if( qorgPopulation     === null ){
    throw new Error( "\n AutomatedTask ConfigError:" +
                     " Qorg {A} is null \n" );
  }
// com.questetra.bpms.core.event.scripttask.WorkflowEngine
// https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#WorkflowEngine


//// == Calculating / 演算 ==
let   listQusers = quserDao.findByQgroup( qorgPopulation );
  if( listQusers === null ){
    throw new Error( "\n AutomatedTask UnexpectedQorgError:" +
                     " Qorg {A} has no member \n" );
  }
let numOfQusers = listQusers.size() - 0;
// com.questetra.bpms.core.event.scripttask.QuserDaoWrapper
// https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#QuserDaoWrapper

let arrQusers = [];
for( let i = 0; i < numOfQusers; i++ ){
  arrQusers.push( (listQusers.get(i).getEmail() + "") );
  // com.questetra.bpms.core.event.scripttask.QuserView
  // https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#QuserView
}
if( strExcludedMembers !== "" ){
  let arrExcludedMembers = strExcludedMembers.split('\n');
  for( let i = 0; i < arrExcludedMembers.length; i++ ){
    let numId = arrQusers.indexOf( arrExcludedMembers[i] );
    if( numId > -1 ){
      arrQusers.splice( numId, 1 ); // remove 1 element at `numId`
    }
  }
}
if( arrQusers.length === 0 ){
  throw new Error( "\n AutomatedTask UnexpectedQorgError:" +
                   " Population is Zero \n" );
}

let numRand = Math.floor( Math.random() * arrQusers.length );
engine.log( " AutomatedTask numRand: " + numRand +
            " (" + arrQusers.length + ")" );
let strSelected = arrQusers[ numRand ];
let quserSelected = quserDao.findByEmail( strSelected );
// com.questetra.bpms.core.event.scripttask.QuserDaoWrapper
// https://questetra.zendesk.com/hc/ja/articles/360024574471-R2300#QuserDaoWrapper


//// == Data Updating / ワークフローデータへの代入 ==
engine.setData( quserPocketSelected, quserSelected );


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

/*
Notes:
- When the process reaches the automated task, the Qorg settings of the Workflow Platform are referred.
    - To explicitly and automatically determine the person in charge.
    - The Process Status "Offered" is avoided.
APPENDIX:
- The random number generation depends on `Math.random()` (JavaScript).
    - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

Notes-ja:
- 案件が自動処理工程に到達した際、ワークフロー基盤の Qorg 設定を参照し、一人を抽出します。
    - 明示的・自動的に担当者を決めたい場合などに利用されます。
    - プロセス状態「引き受け待ち」を回避できます。
APPENDIX-ja:
- 乱数の生成分布は `Math.random()` (JavaScript) に依存します。
    - https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Math/random
*/

Download

2021-10-11 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/quser-set-one-user-of-qorg-randomly-2021/
The Add-on import feature is available with Professional edition.
Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.

Notes

  • When the process reaches the automated task, it refers to the Qorg settings of the workflow infrastructure and extracts one person.
    • This is used when you want to decide the person in charge explicitly and automatically.
    • The Process Status “Offered” can be avoided.

Capture

Extracts one user from the members of Qorg randomly and sets that user in Quser data. It is also possible to exclude specific users from the extraction target. If there are no candidates in the population, an error will occur.
Extracts one user from the members of Qorg randomly and sets that user in Quser data. It is also possible to exclude specific users from the extraction target. If no candidates in the population, an error will occur.

Appendix

See also

Leave a Reply

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

%d bloggers like this: