« Back to AAU Project

Adding reference models autonomously (two sided)

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
We have the following problem:
suppose we have an attribute of type "INTERREF" named "Participating" of class "XX", now, when we choose an instance "harold" of class "person" (which is created in an other model) as reference model  to be set into "participating" of class "XX",
then,
the attribute "participating" in the intance class "harold" should be set  autonomously to the model "XX" as a reference.
Would you please post an example!
Thank you in advance.

RE: Adding reference models autonomously (two sided)
Answer
06/08/15 09:30 as a reply to Fadi Al Machot.
To create such an reference as an inverse of the actual one created can be achieved using events and AdoScript. Please be aware that the system is already aware of the backlink itself, not explicitly as an attribute but within script and querying functionalities of ADOxx. To give you examples how to see this examples, please consider the following approaches already provided by the platform.

+ UI - see pointing-at relations through the Object reference context menu entry: For any objects you can right-clcik and select the "Object reference" entry. This will return a clickable list of all other instances referencing the object. These objects can also be moved to others (all, single one) or used as a report

+ AQL:
it is possible to query all pointers using AQL using "<--". An example would look like

1{"Document-4711"} <--

This would return all pointing instance IDs to the object named "Document-4711".

+ AdoScript: you can execute the AQL of above using AdoScript using the

1CC "AQL" EVAL_AQL_EXPRESSION expr:strValue ( modelid:intValue | modelscope )
2#RESULT ecode:intValue objids:strValue

or use the direct command
1
2CC "Core" GET_INCOMING_INTERREFS Target [ sourcemodelids:strValue ] .
3Target : objid:intValue | modelid:intValue .
4# RESULT ecode:intValue reftext:references

Automatically create INTERREFs based on INTERREFs
Using events, you can also perform the behaviour to create a (redundant) INTERREF. Please be aware that this script needs heavy testing and validation as there are assumption with respect to the metamodel and availability of attributes, but it should give you a hint how things are done. In addition, redundancies are not checked and corrected. Please let us know if you need further details here.

 1ON_EVENT "AfterEditAttributeValue" {
 2  # instid : integer    ID of the changed instance.
 3  # attrid : integer    Attribute ID.
 4  # modelid : integer    ID of the model containing the changed instance.
 5  SET nCurrentObjID: (objid)
 6  SET nCurrentModelID: (modelid)
 7  SET nCurrentAttrID: (attrid)
 8  CC "Core" GET_CLASS_ID objid: (nCurrentObjID)
 9  SET nCurrentClassID: (classid)
10  CC "Core" GET_ATTR_ID classid: (nCurrentClassID) attrname: "Participating"
11  SET nParticipatingAttrID: (attrid)
12  # only continue if the correct ID
13  IF (nCurrentAttrID = nParticipatingAttrID) {
14    # get the created INTERREF count
15    CC "Core" GET_INTERREF_COUNT objid: (nCurrentObjID) attrid:(nParticipatingAttrID)
16    # get value of latest
17    CC "Core" GET_INTERREF objid: (nCurrentObjID) attrname:"Participating" index: (count)
18    SET nTargetObjectID: (tobjid)
19    SET nTargtClassID: (tclassid)
20    # TODO: Potentially LOAD model to be able to modify
21    # get the attribute ID of the target class attribute, assumption the INTERREF DOMAIN is correct
22    CC "Core" GET_ATTR_ID classid: (nTargetClassID) attrname:"Participating"
23    SET nTargetParticipatingID: (attrid)
24    CC "Core" ADD_INTERREF objid: (nTargetObjectID) attrid: (nTargetParticipatingID) tobjid: (nCurrentObjID)
25  }
26}

RE: Adding reference models autonomously (two sided)
Answer
10/08/15 09:16 as a reply to Wilfrid Utz.
Thank you Wilfrid,
what is the event to know if the user did click the "+" to add a reference model, or if he did click "*" to delete a reference model?
Currently, I am using  the event "AfterEditAttributeValue" which works for both without knowing what is the clicked choice.