Wiki source code of Operations
Hide last authors
1.1 | 1 | = Operations = | |
2 | |||
3 | Operations are ?Functions? that apply on the entity (on one entity or a set of entities). | ||
4 | For example the "Save" operation stores the entity in the database. | ||
5 | |||
6 | 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". | ||
7 | |||
8 | Recommendation: Use an upper case first letter for operations names. For example: Save (an not save). | ||
9 | First letter as lower case is used for actions (See user actions). | ||
10 | |||
11 | [[image:img13.png||alt="Operation"]] | ||
12 | |||
13 | == Operations and Transactions == | ||
14 | |||
15 | Operations are executed within a transaction. If the operation fails (for any reason), the entire operation will be rolled back (as a database transaction). | ||
16 | |||
17 | |||
18 | == Operations Steps == | ||
19 | |||
20 | Operations are build of a series of steps. Those steps are executed in the specified order. | ||
21 | |||
22 | Steps can be: | ||
23 | * Parent: calls the operation of the parent entity when the entity is a derived entity. | ||
24 | * Database step: This can be save, search, load, count and delete. | ||
25 | * Document step: Manipulates the entity in memory: New or Copy | ||
26 | * Rule based step: See Rules based operation | ||
27 | * Workflow: triggers a workflow | ||
28 | * Script: Certainly the most important type. Using javascript you can query, update, delete all entities in the database. | ||
29 | |||
30 | |||
31 | = Operations and Scripting = | ||
32 | |||
33 | Script steps are used to manipulate entities. Scripts can be as simple as: | ||
34 | |||
35 | {{code language="JavaScript"}} | ||
36 | data.custField1 = "Test"; | ||
37 | {{/code}} | ||
38 | |||
39 | |||
40 | == Entites and scripts == | ||
41 | |||
42 | You may call operations in scripts. Operations are methods of the entity. | ||
43 | |||
44 | |||
45 | {{code language="JavaScript"}} | ||
46 | // simple operation calls | ||
47 | var e = myEntity.New(); | ||
48 | e.myProp = ?toto?; | ||
49 | e.Save(); | ||
50 | {{/code}} | ||
51 | |||
52 | In this example, New and Save are 2 operations. | ||
53 | |||
54 | |||
55 | == Accessing references == | ||
56 | |||
57 | You can get references (one or many) as an entity, or a list (for the many): | ||
58 | |||
59 | {{code language="JavaScript"}} | ||
60 | // access to referential properties | ||
61 | var e = myEntity.Get(?45566777553434556?); // this is a Get by sysId | ||
62 | var ref1 = e.myRefProp; | ||
63 | var propOfRef1 = ref1.myProp; | ||
64 | // access to many ref | ||
65 | var lst = e.myManyRefProp; | ||
66 | print(lst.length); | ||
67 | {{/code}} | ||
68 | |||
69 | |||
70 | == Setting References == | ||
71 | |||
72 | You can set references as well directly from the scripts: | ||
73 | |||
74 | {{code language="JavaScript"}} | ||
75 | // set referential entity | ||
76 | var paul = rqEmployee.Get(?233455667775444?); // Get by sysId | ||
77 | var e = myEntity.Get(?45566777553434556?); | ||
78 | e.myRefProp = paul; | ||
79 | e.Save(); | ||
80 | |||
81 | var lst = new Array(); | ||
82 | lst.push(paul); | ||
83 | e.myManyRefProp = lst; | ||
84 | e.Save(); | ||
85 | {{/code}} | ||
86 | |||
87 | or: | ||
88 | |||
89 | {{code language="JavaScript"}} | ||
90 | e.myManyRefProp = [paul]; | ||
91 | e.Save(); | ||
92 | {{/code}} | ||
93 | |||
94 |