Link people and companies
An employment connects a person to a company and carries one or more roles. A person can work at several companies, a company has many employees. You can manage the link from either side. The result is the same.
const customers = sdk.asAdmin().Customers()
Add or change an employment
// From the company
await customers.OU.upsertEmployee('SC-COMPANY', 'SC-PERSON', [
{ role: 'ceo', status: 'active' }
])
// From the person, same effect
await customers.Person.upsertEmployment('SC-PERSON', 'SC-COMPANY', [
{ role: 'ceo', status: 'active' }
])
upsert means: create the link, or replace the roles of the existing link. roles must be a non-empty array.
| Property | Values |
|---|---|
role | Free text. The catalog contains ceo and employee |
status | active, paused, separated, retired, inactive |
Pass { return: true } as fourth argument to get the updated entity back.
Several roles
await customers.OU.upsertEmployee('SC-COMPANY', 'SC-PERSON', [
{ role: 'employee', status: 'active' },
{ role: 'ceo', status: 'paused' }
])
Remove the link
await customers.OU.removeEmployee('SC-COMPANY', 'SC-PERSON')
await customers.Person.removeEmployment('SC-PERSON', 'SC-COMPANY')
Someone leaves the company
Keep the history instead of deleting:
await customers.OU.upsertEmployee('SC-COMPANY', 'SC-PERSON', [
{ role: 'employee', status: 'separated' }
])
Errors
| Error | Meaning |
|---|---|
relationship/roles-required | roles missing or empty |
relationship/role-missing | A role entry has no role |
relationship/invalid-status | Status not in the list above |
entity/wrong-entity-type | The id you passed as company is not a company (or the person id not a person) |
entity/not-found | Unknown humanId, or hidden by group ACLs |