model object we got back from
workingCopy.model() can be used to find and even manipulate units and elements. It provides three different means with which we can find units and elements.
2 The model.root Property
root object refers to the
root project node in the Project Explorer in Studio Pro, and from here on you can walk through the project tree and into specific documents. The following line for examples finds the name of the first attribute of the
Customer entity in the first module of your project.
const model = workingCopy.model(); const domainModel = model.root.modules.domainModel; const customerEntity = domainModel.entities.filter(entity => entity.name === "Customer") const attributeName = customerEntity.attributes.name;
3 The model.allXXX() Functions
These functions return the complete collection of a specific type of units. Some unit types are abstract, for example
allMicroflowBases returns all microflows and all rules. So the snippet above could also be expressed as:
const domainModel = model.allDomainModels(); const customerEntity = domainModel.entities.filter(entity => entity.name === "Customer") const attributeName = customerEntity.attributes.name;
4 The model.findXXXByQualifiedName() Functions
For all referable concepts in a model (both units, such as a page, as well as elements, such as an entity) a
find function is exposed through the
model object. Given a fully-qualified name (for example
"Customers.Customer.Name") it finds the element with that name, or it returns
null if it doesn’t exist.
const customerEntity = model.findEntityByQualifiedName("Customers.Customer"); const attributeName = customerEntity.attributes.name;
Continue with How to Load Units and Elements.