Examples
Example #1
This example fetches the ID of a person role and then creates a new actor by setting their first name, last name, email, and phone number. You can separate these calls, for example, preload all required ID's in initialization and then just pass it as array.
// Call role service to get role ids
this.roleApiService.getRoleBySystemName({ systemName: 'Person' })
.then(responce => {
let role = responce.errorOrValue.value.value;
// Model Updates
let personFieldset = new ChangePersonFieldsetUpdate();
personFieldset.firstName = { value: 'Darth' };
personFieldset.lastName = { value: 'Vader' };
personFieldset.genderCode = { value: GenderCode.Male };
let email = new AddEmailUpdate();
email.address = 'darth.vader@galary.empire.gov';
email.makePrimary = true;
let phone = new AddPhoneModelUpdate();
phone.phoneNumber = '+1 000 000 00 00';
phone.phoneKind = PhoneKind.Office;
// Create command with required information
let command = new CreateActorCommand();
command.modelUpdates = [personFieldset, email, phone];
command.roleIds = [role.id];
// Call actor service to create actor
this.service.createActor(command).then(response => console.log('success'));
});
Example #2
This example demonstrates how to create a new custom field (type = string) and then use it when creating an actor.
// Create new custom field (type = string)
let command = new CreateEavFieldCommand();
command.displayName = 'Custom Field';
command.fieldTypeSystemName = 'String';
command.systemName = 'CustomField';
this.fieldApiService.createEavField(command)
.then(r => {
console.log('success');
})
.catch(r => console.error('error'));
// --- some code ---
// Call role service to get role ids
this.roleApiService.getRoleBySystemName({ systemName: 'Person' })
.then(response => {
let role = response.errorOrValue.value.value;
// Model Updates
let personFieldset = new ChangePersonFieldsetUpdate();
personFieldset.firstName = { value: 'Darth' };
personFieldset.lastName = { value: 'Vader' };
personFieldset.genderCode = { value: GenderCode.Male };
let email = new AddEmailUpdate();
email.address = 'darth.vader@galary.empire.gov';
email.makePrimary = true;
let phone = new AddPhoneModelUpdate();
phone.phoneNumber = '+1 000 000 00 00';
phone.phoneKind = PhoneKind.Office;
let setField = new SetStringEavValueModelUpdate();
setField.fieldSystemName = 'CustomField';
setField.value = 'Value';
// Create command with required information
let command = new CreateActorCommand();
command.modelUpdates = [personFieldset, email, phone, setField];
command.roleIds = [role.id];
// Call actor service to create actor
this.service.createActor(command).then(response => console.log('success'));
});
Example #3
This example demonstrates how to convert CustomerPerson
to CustomerOrganization
and vice versa.
Step 1: Create CustomerPerson
URL: http://localhost:9000/api/actors/actor/createActor
Request Body
{
"modelType": "CreateActorCommand",
"modelUpdates": [
{
"modelType": "AddEmailUpdate",
"address": "test@gmail.com",
"isInvoice": { "value": true }
},
{
"modelType": "AddPhoneModelUpdate",
"phoneNumber": "123456",
"phoneKind": 3
},
{
"modelType": "ChangePersonFieldsetUpdate",
"firstName": { "value": "a_person" },
"lastName": { "value": "customer" }
}
],
"roleNames": ["CustomerPerson", "Person", "Customer"]
}
Step 2: Change from CustomerPerson to CustomerOrganization
URL: http://localhost:9000/api/actors/actor/updateActor
Request Body
{
"modelUpdates": [
{
"modelType": "RemoveRoleFromActorModelUpdate",
"roleId": 8
},
{
"modelType": "RemoveRoleFromActorModelUpdate",
"roleId": 1
},
{
"modelType": "AddRoleToActorModelUpdate",
"roleId": 9
},
{
"modelType": "AddRoleToActorModelUpdate",
"roleId": 2
},
{
"modelType": "ChangeOrganizationFieldsetUpdate",
"organizationName": { "value": "a_person" }
}
],
"modelType": "UpdateActorCommand",
"entityId": 11
}
Step 3: Change from CustomerOrganization to CustomerPerson
URL: http://localhost:9000/api/actors/actor/updateActor
Request Body
{
"modelUpdates": [
{
"modelType": "RemoveRoleFromActorModelUpdate",
"roleId": 9
},
{
"modelType": "RemoveRoleFromActorModelUpdate",
"roleId": 2
},
{
"modelType": "AddRoleToActorModelUpdate",
"roleId": 8
},
{
"modelType": "AddRoleToActorModelUpdate",
"roleId": 1
},
{
"modelType": "ChangePersonFieldsetUpdate",
"firstName": { "value": "a_person" }
}
],
"modelType": "UpdateActorCommand",
"entityId": 11
}
note
Role IDs may vary across different tenants. The GetRoles
method should be used to resolve them by system names.