« Back

Mandatory attributes check

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mandatory attributes check
community attrrep documentation query adoscript
Answer
3/27/14 11:46 AM
I want to make something similar to the cardinality check, with the mandatory attributes. Before the metamodel is saved, I want to call a function that checks all mandatory attributtes are setted. If the result is ok, the metamodel should be saved, in other case it must show an error message to the user. Is it possible to do that?

RE: Mandatory attributes check
Answer
3/7/14 1:52 PM as a reply to Anonymous.
I have managed to implement a solution for running an automated "mandatory check" before saving a model. I've attached the application library in ABL format, including the script file, and also the script file  (ASC).
Below a short descriprion of the algorithm implemented in the script:
 1- read model id from the global variable
 2- get all objects
 3- for each object
 4  - read value of the class attribute AttrRep
 5  - call procedure GET_MANDATORY_ATTRIBUTES for parsing the AttrRep and identifying the mandatory attributes
 6  - for each mandatory attribute
 7    - get attribute value
 8    - get default value
 9    - if attribute is of type RECORD
10      - if no rows
11        - add line to the errorlist: Object name, attribute name
12      - else
13        - get record class information
14        - read class attribute AttrRep of the record class
15        - parse AttrRep for identifying mandatory attributes of the record class (columns)
16        - for each row
17          - get row ID
18            - for each mandatory attribute in the record class (column)
19              - get value of the mandatory attribute for the current row (value of the cell)
20              - get default value of the mandatory attribute for the current row (default value of the cell)
21              - if the two values are equal
22                - add entry to the errorlist: object name, attribute name, column name
23              endif
24            endfor
25        endfor
26      endif
27    - else
28      - if the two values are equal
29        - add entry to the errorlist: object name, attribute name
30      endif
31    endif
32  endfor
33endfor
34
35- if the errorlist is not empty
36  - show error dialog containing the list of errors of mandatory check
37  - if the endbutton is "no"
38    - set global variable nMandatoryCheckExitValue to -1
39  endif
40endif

   
procedure GET_MANDATORY_ATTRIBUTES
1- get next occurrence of the modifier "mandatory"
2- while the modifier "mandatory" is found
3  - find the corresponding attribute
4  - add the attribute to the attribute list
5  - get next occurrence of the modifier "mandatory"
6end while

In the library attribute ExternalCoupling, an event handler is implemented for the event BeforeSaveModel.
The handler saves the ID of the model to be saved in a global variable and calls the script file.
After running the script file, the event handler reads the global variable g_nMandatoryCheckExitValue and uses it as an exit parameter: (-1: don't save, throw no error; 0: save, throw no error)
Attachments: Sample_MandatoryCheck.abl (28.2k), test_mandatory.asc (4.8k)