# Triggers: Script Tips

## Triggers: Script Tips

Here we will show you some tips about how to use scripts.

<p class="callout info">For more information you can visit the [official documentation of Soffid](http://www.soffid.org/doc/console/latest/uml/index.html)</p>

#### Write into a sync-server log

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

#### Recover data from a Soffid object when synchronizing

<p class="callout warning">***\* source** only can be used in outgoing triggers. That object will be Soffid format.*</p>

<p class="callout warning">***\* newObject** and **oldObject** can be used in outgoing and incoming triggers. Those objects will be target system format in outgoing triggers and will be Soffid format in incoming triggers.*</p>

##### Recover data from Soffid object to synchronize

Recover user name

```Java
name = source{"userName"};
```

##### Recover a custom attribute

Recover company (company could be a user custom attribute defined on metadata page)

```Java
comp = source{"attributes"}{"company"};
```

##### Recover the attribute value that will be sent

```Java
no = newObject{"userName"};
gn = newObject{"givenName"};
....

```

##### Recover the attribute value from the select

That info comes from the target system. In a synchronization process, the first thing that Soffid does, is to query if the account exists on the target system.

```Java
no = oldObject{"userName"};
gn = oldObject{"givenName"};
....
```

#### Use existing services

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

```

#### Create a new Soffid object

```Java
mailDomain = new com.soffid.iam.api.MailDomain();
newUser = new com.soffid.iam.api.User();
newRol = new com.soffid.iam.api.Role();
............

```

#### Loop an object list

```Java
for(role : roleList){
  //TO-DO
  out.print(" Role: " + role.roleName + "\n");
}
```

#### Recover response

```Java
if (response!=null) {
  for (o : response.getObjects()) {
    if (o!=null && o{"result"}!=null) {
      //TO-DO
    }
  }
}
```

#### Send a text email 

```Java
serviceLocator.getMailService().sendTextMail("mail@soffid.com", "Subject", "Mail message");
```

#### Send a HTML mail 

```Java
serviceLocator.getMailService().sendHtmlMailToActors(<to>, <subject>, <html-body>);
```