Operations
Operations
Operations are "Functions" that apply on the entity (on one entity or a set of entities).
For example the "Save" operation stores the entity in the database.
Operations can be as simple as the "Save" operation or much more complex like "Decrease inventory level when an item is taken out of the stock".
Recommendation: Use an upper case first letter for operations names. For example: Save (an not save).
First letter as lower case is used for actions (See user actions).
Operations and Transactions
Operations are executed within a transaction. If the operation fails (for any reason), the entire operation will be rolled back (as a database transaction).
Operations Steps
Operations are build of a series of steps. Those steps are executed in the specified order.
Steps can be:
- Parent: calls the operation of the parent entity when the entity is a derived entity.
- Database step: This can be save, search, load, count and delete.
- Document step: Manipulates the entity in memory: New or Copy
- Rule based step: See Rules based operation
- Workflow: triggers a workflow
- Script: Certainly the most important type. Using javascript you can query, update, delete all entities in the database.
Operations and Scripting
Script steps are used to manipulate entities. Scripts can be as simple as:
Entites and scripts
You may call operations in scripts. Operations are methods of the entity.
var e = myEntity.New();
e.myProp = ?toto?;
e.Save();
In this example, New and Save are 2 operations.
Accessing references
You can get references (one or many) as an entity, or a list (for the many):
var e = myEntity.Get(?45566777553434556?); // this is a Get by sysId
var ref1 = e.myRefProp;
var propOfRef1 = ref1.myProp;
// access to many ref
var lst = e.myManyRefProp;
print(lst.length);
Setting References
You can set references as well directly from the scripts:
var paul = rqEmployee.Get("233455667775444"); // Get by sysId
var e = myEntity.Get("45566777553434556");
e.myRefProp = paul;
e.Save();
var lst = new Array();
lst.push(paul);
e.myManyRefProp = lst;
e.Save();
or:
e.Save();