Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Record and Interref
Answer
6/18/14 1:14 PM
Hi,

I am storing model references (Interrefs) within a column in a record table. I would like to add new rows, and therefore new Interrefs using AdoScript.
However, I didn't find the solution on my own as the Interrefs, to my knowledge, aren't added with SET_ATTR_VAL but by ADD_INTERREF instead.

Any help would be highly appreciated. emoticon

RE: Record and Interref
Answer
6/26/14 11:43 AM as a reply to Anonymous.
Thank you for your questions. This is possible in ADOxx - the important aspect to keep in mind is that record rows are understood by the platform as instances of classes, attributes/columns of a record have therefore an attribute ID similar as for modelling instances.
Below a code snipplet in AdoScript that shows the approach to add programmatically INTERREFs to a record row in a specific column. For the example the following structure is assumed:

+ A recordclass is defined with two columns/attributes "Key", of type instance INTERREF and "Value" of type INTEGER
+ The actual object ID to run upon are hard-coded
+ The INTERREF is set using a target objectID also hard-coded in the example
+ The class name in the example is "Element" and holds the record called "Key Value Pair"

 1# static example IDs for actual instance to run the script upon and the target of the new INTERREF
 2SETL nCurrentObjID: (336409)
 3SETL nToObjID: (336403)
 4
 5# assumes that a column is of INTERREF and named "Key" and another column is of type INTEGER and named "Value"
 6CC "Core" GET_CLASS_ID classname:"Element"
 7SETL nClassID: (classid)
 8CC "Core" GET_ATTR_ID classid: (nClassID) attrname:"Key Value Pair"
 9SETL nRecAttrID: (attrid)
10# Create a new record row in the "Key Value Pair" table and remember the ID of the new row
11CC "Core" ADD_REC_ROW objid: (nCurrentObjID) attrid: (nRecAttrID)
12SETL nNewRowID: (rowid)
13# Check with debug if this worked, by counting the rows in the table
14CC "Core" debug GET_REC_ATTR_ROW_COUNT objid: (nCurrentObjID) attrid: (nRecAttrID)
15# assumes an instance INTERREF
16# get the classID of the new row, dynamically
17CC "Core" debug GET_CLASS_ID objid: (nNewRowID)
18SETL nRowClassID: (classid)
19# get the attribute ID of the INTERREF column
20CC "Core" GET_ATTR_ID classid: (nRowClassID) attrname: ("Key")
21SETL nColumnKeyAttrID: (attrid)
22# Set the values
23CC "Core" ADD_INTERREF attrid: (nColumnKeyAttrID) objid: (nNewRowID) tobjid: (nToObjID)
24CC "Core" SET_ATTR_VAL objid: (nNewRowID) attrname:"Value" val:10

RE: Record and Interref
Answer
7/8/14 7:45 AM as a reply to Wilfrid Utz.
Thank you very much for the answer. Worked fine!!