« Back to AAU Project

Unique Values for Records (tables)

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Unique Values for Records (tables)
Answer
6/22/15 10:15 AM
How can we define the attributes (columns) of a specific record to be unique, For example in my case the user should not be able to add 2 similar values of the attribute „Name“ in the record (table) „Attributes“ .

RE: Unique Values for Records (tables)
Answer
6/22/15 11:44 AM as a reply to Fadi Al Machot.
Dear Fadi,

Thank you for your question. To solve your problem use can use the event listener called "AfterEditAttributeValue". If you trigger this event if the record content if editted and compare the values of the column, you are able to set conditions (e.g. uniqueness). Please find attached an example library with an initial solution where the folllowing AdoScript code is integrated in the 'External coupling'-library attribute.

 1ON_EVENT "AfterEditAttributeValue" {
 2#Save the predefined parameters of the event
 3  SET id_ModelId: (modelid)SET id_InstId: (instid)
 4  SET id_AttrId: (attrid)CC "Core"
 5
 6#Trigger the event only if the Table attribute is editted
 7  GET_CLASS_ID classname:"A"
 8  CC "Core" GET_ATTR_ID classid: (classid) attrname:"Table"SET nTableAttrId: (attrid)
 9  IF (nTableAttrId=id_AttrId) {   
10#Get all row ids and save them in a list   
11    CC "Core" GET_ALL_REC_ATTR_ROW_IDS objid: (id_InstId) attrid: (id_AttrId)   
12    SET sRowids: (rowids)
13#Compare attribute values of the attribute "Value"
14    FOR i in: (sRowids) {   
15      CC "Core" GET_ATTR_VAL objid: (VAL i) attrname:"Value"   
16      SET nVal1: (val)   
17      SET sRowCompare: (tokdiff(sRowids,i))     
18      FOR j in: (sRowCompare) {     
19      CC "Core" GET_ATTR_VAL objid: (VAL j) attrname:"Value"     
20      SET nVal2: (val)               
21        IF (nVal1=nVal2) { 
22#If the values are equal then give a warning.
23        CC "AdoScript" ERRORBOX "Not Allowed!!!"         
24        }     
25      }   
26  SET sRowids: (tokdiff(sRowids,i))   
27    }
28  }
29}
Attachments: Unique Values for Records Library.abl (10.5k)