Skip to main content

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.

PropertyValues
roleFree text. The catalog contains ceo and employee
statusactive, 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' }
])
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​

ErrorMeaning
relationship/roles-requiredroles missing or empty
relationship/role-missingA role entry has no role
relationship/invalid-statusStatus not in the list above
entity/wrong-entity-typeThe id you passed as company is not a company (or the person id not a person)
entity/not-foundUnknown humanId, or hidden by group ACLs