- Home [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
- Getting started
- Manage types
- Global context and isolation
- Manage apps
- Batch actions with app items
- Manage external services
- Scripts in widgets
- Web components
- Access permissions
- Getting started with processes
- Getting started with signatures
- Getting started with file previews
- Getting started with the organizational chart
- Getting started with users and groups
-
Getting started with the
Table data type - Use cases
- How to set up custom view of app items
- How to set up dynamic display of fields and widgets with a complex condition
- How to register a document
- How to calculate the number of days between two dates
- How to create a substitution for a user
- How to use pagination and sorting when searching for app items
- API
- Object types
- Data types
- Global constants
- Work with apps
- Web requests
- Access permissions
- Document flow
- Live Chats
- “Code” widget
- Signatures
- Business calendars
- Integration with IP telephony
- Integration with email marketing services
In this article
Getting started with the organizational chart
You can access the organizational chart using the System object:
const item = System.organisationStructure;
Create an org chart item
You can create a new org chart item using the OrganisationStructure.createItem method:
const item = System.organisationStructure.createItem('Director of Development', OrganisationStructureItemType.Position);
In this example, Director of Development is the name of the org chart item that needs to be created, and OrganisationStructureItemType.Position is the type of this org chart item.
There are three types of org chart items:
Add an org chart item
To add a new org chart item into an existing organizational chart (to a specified parent), you can use the OrganisationStructureItem.addChild method:
const tree = await System.organisationStructure.fetchTree(); tree.getRoot().addChild(item);
Get the current organizational chart
You can get the current org chart tree using the OrganisationStructure.fetchTree method:
const tree = await System.organisationStructure.fetchTree();
Find an org chart item
You can find an org chart item by its name using the OrganisationStructureTree.find method. The method will return the item or
undefined
if no such item exists.// Getting the current org chart tree const tree = await System.organisationStructure.fetchTree(); // Finding the item names CEO and writing it to a variable const ceo = tree.find('CEO');
Find the root item of the org chart
You can get the root item of the org chart, that is, the highest element in the hierarchy, using the OrganisationStructureTree.getRoot method:
const root = tree.getRoot();
Validate the org chart
You can check the org chart for errors and view the errors found in the process using the OrganisationStructureTree.validate method. If validation fails, the method returns an array with errors. If validation is successful, an empty array is returned. We recommend to validate the org chart when you modify it using scripts, as this can cause errors, unlike visual editing in the Administration workspace.
// Writing the current org chart into a variable const tree = await System.organisationStructure.fetchTree(); // Writing an array or errors returned after validation into a variable const errs = await tree.validate(); // Setting a condition: if the array of errors includes more than 0 items, if (errs.length > 0) { // these items need to be written to a string with the `join` method; a separator is set Context.data.errors = errs.join(', '); } else { // If the array of errors is empty, the corresponding message needs to be passed to the string Context.data.errors = 'The org chart is correct'; }
Possible errors
Save a tree as the current org chart
The method allows you to save the configured org chart tree as the current organizational chart. Before saving, the org chart will be automatically validated (see the description of validation in the example above).
const errs = await System.organisationStructure.save(tree); if (errs.length === 0) { // Saved successfully }
In this example,
tree
is the org chart that needs to be saved.Find all departments and write them to a Category type field
// Finding all departments in the org chart using the DEPARTMENT item type as a filter const deps = await System.organisationStructure.search().where(i => i.type.like('DEPARTMENT')).all(); // Iterating through each of the items and setting the starting value of the counter to generate uniqure codes let counter = 1; for (let item of deps) { // Writing Category field type values into the `variants` variable const variants = Context.fields.category1.data.variants; // If the org chart item has a name, if (item.data.name) { // a new entry appears in the Category type field. It is assigned a name and a unique code. The counter’s value is increased variants.push({ code: 'item'+counter.toString(), name: item.data.name }); \t\t} \t\tcounter ++; \t}