Check The User Is In The Organization
If the specified User is the leader of the specified Organization this task returns “L”. If they are one of the its members it returns “M”. If the User doesn’t belong to the Organization it returns nothing.
(C) Questetra, Inc. (MIT License)
Configs
  • A: Set OAuth2 Config Name (at [OAuth 2.0 Setting]) *
  • A2: Set Application-Root URI ( https:// … ) * #{EL}
  • B: Select STRING/CHECKBOX DATA for Qrole Id (Role Id) *
  • C: Select STRING/USER DATA for Quser Email *
  • X: Select STRING DATA for Access Log (update)
Script (click to open)

main();
function main(){
//////// START "main()" /////////////////////////////////////////////////////////////////
//// == Config Retrieving / 工程コンフィグの参照 ==
const userPocket = configs.getObject("userField");
const orgPocket = configs.getObject("orgField");
const strPocketResult = configs.getObject("result");

//// == Data Retrieving / ワークフローデータの参照 ==
const user = engine.findData( userPocket );
const org =  engine.findData( orgPocket );

//// == Calculating / 演算 ==
errorCheck(user, org);
let result = "";
if (check(true, user, org)) {
  result = "L";
}else if (check(false, user, org)) {
  result = "M";
}

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

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


//Check whether the user is the leader or a staff member in the org
function check(LM, user, org){
  let temp;
  const userList = quserDao.findByQgroupAndPosition(org, LM);
  for (let i = 0; i < userList.size(); i++) {
    temp = userList.get(i);
    if(user.getId() == temp.getId()){
      return true;
    }
  }
}

// Check for the existence of user and org.
function errorCheck(user, org){
  if (org == null && user != null) {
    throw "Organization Not Selected";
  }else if (org != null && user == null) {
    throw "User Not Selected";
  }else if (org == null && user == null){
    throw "Organization and User Not Selected";
  }

  const userC = quserDao.findById(user.getId());
  const orgC = qgroupDao.findById(org.getId());
  if (userC == null && orgC != null) {
    throw "Selected user doesn't exist";
  }else if (userC != null && orgC == null) {
    throw "Selected Organization doesn't exist";
  }else if (userC == null && orgC == null){
    throw "Selected Organization and User don't exist";
  }
}

Download

Capture

Leave a Reply

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

%d bloggers like this: