Skip to main content

Incoming triggers examples

Load triggers

When you are configuring an agent, depending on the connector type, , it will be able to define BeanShell scripts that will be triggered when data is loaded into Soffid (incoming triggers).

Triggers can be used to validate or perform a specific action just before performing an operation or just after performing an operation into Soffid objects. 

The trigger result will be a boolean value, true to continue or false to stop.

Use case examples

Example 1

A user can have more than one account on a target system. We want to reconcile only those accounts which have the same name on Soffid and on target system.

name = newObject{"accountName"};
uaList = serviceLocator.getAccountService().findUsersAccounts(name,"agentName");

for(userAccount: uaList) {
  if (userAccount.name.equals(name)) {
    return true;
  } else  {
    return false;
  }
}

return false;

Example 2

Update only users who belong to Soffid company.

name = newObject{"accountName"};
user = serviceLocator.getUserService().findUserByUserName(name);

if (user != null) {
  attributes = serviceLocator.getUserService().findUserAttributes(name);
  company = attributes.get("company");
  if (company != null && company.equals("Soffid")) {
  	return true;
}
return false;
  

Example 3

Discard to create some accounts (PreInsert account).

System.out.println("************** Pre Insert Account");
cuentas = new java.util.HashMap();
cuentas.put("admin",null);
account = newObject{"accountName"};

if (cuentas.containsKey(account)) {
  System.out.println("TRIGGER ACCOUNT PREINSERT - Discarded to create the account " + account);
  return false;
}

System.out.println("TRIGGER ACCOUNT PREINSERT - Correct account " + account);
return true;

Example 4

Avoid deleting users (PreDelete user).

return false;

Tips

Write into sync-server log

System.out.println("what you want......");

Use  existing services

serviceLocator.getUserService().....
serviceLocator.getAccountService().....
serviceLocator.......