Update attribute values at different elementsUpdate attribute values at different elementsRE: Update attribute values at different elementsMateusz Dziedzichttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=10729252017-12-07T12:02:34Z2017-12-07T12:00:14ZRegarding 2.:<br />In order to make the solution in 1. work also outside the current model, some adaptations have to be made in the update.asc file (section 2)). You will find below the adapted code for the update.asc file and the code for the procedure used in update.asc. <br />In the procedure you use the GET_MODEL_GROUP_TREE_XML, which generates an XML string containing the current model group tree structure. Thus, this XML string also contains modelids of all models. In the next step you search for the <model> tags in the XML string and copy the value of the attribute id to a string called lModelIDs. The result is a list of all modelids. The adaptation in the update.asc file is, that you (FOR-) loop through the modelids list to get the objects of class A from all models. The result is a list of all objects of class A not just from the current model, but from all models. <br /><br />2) update.asc:<div class="code"><span class="code-lines"> 1</span>CC "Core" GET_CLASS_ID objid: (nInstId)<br /><span class="code-lines"> 2</span>#-->RESULT ecode:intValue classid:intValue<br /><span class="code-lines"> 3</span>SETL nClassID: (classid)<br /><span class="code-lines"> 4</span><br /><span class="code-lines"> 5</span>CC "Core" GET_CLASS_NAME classid: (nClassID)<br /><span class="code-lines"> 6</span>#-->RESULT ecode:intValue classname:strValue isrel:intValue<br /><span class="code-lines"> 7</span>SETL sClassName: (classname)<br /><span class="code-lines"> 8</span><br /><span class="code-lines"> 9</span>IF(sClassName = "A") {<br /><span class="code-lines">10</span> CC "Core" GET_ATTR_NAME attrid: (nAttrId)<br /><span class="code-lines">11</span> #-->RESULT ecode:intValue attrname:strValue<br /><span class="code-lines">12</span> SETL sAttrName: (attrname)<br /><span class="code-lines">13</span><br /><span class="code-lines">14</span> IF(sAttrName = "a3") {<br /><span class="code-lines">15</span> CC "Core" GET_ATTR_VAL objid: (nInstId) attrid: (nAttrId)<br /><span class="code-lines">16</span> #-->RESULT ecode:intValue val:anyValue<br /><span class="code-lines">17</span> SETL sAttrVal: (val)<br /><span class="code-lines">18</span><br /><span class="code-lines">19</span> SETL lObjids: ("")<br /><span class="code-lines">20</span> GET_ALL_MODELIDS lModelIDs: ("") nStartingPointForSearch: (0 ) result:lModelIDs<br /><span class="code-lines">21</span> FOR i from: (0) to: (tokcnt(lModelIDs)-1) {<br /><span class="code-lines">22</span> CC "Core" LOAD_MODEL modelid: (VAL (token(lModelIDs,i)))<br /><span class="code-lines">23</span> #-->RESULT ecode:intValue isloaded:intValue<br /><span class="code-lines">24</span> CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid: (VAL(token(lModelIDs,i))) classname: (sClassName)<br /><span class="code-lines">25</span> #-->RESULT ecode:intValue objids:list<br /><span class="code-lines">26</span><br /><span class="code-lines">27</span> SETL lObjids: (lObjids + objids + " ")<br /><span class="code-lines">28</span> }<br /><span class="code-lines">29</span> FOR i from: (0) to: (tokcnt(lObjids)-1) {<br /><span class="code-lines">30</span> CC "Core" SET_ATTR_VAL objid: (VAL (token(lObjids,i)))attrname: (sAttrName) val: (sAttrVal)<br /><span class="code-lines">31</span> }<br /><span class="code-lines">32</span> }<br /><span class="code-lines">33</span>}<br /></div><br />3) GET_ALL_MODELIDS procedure:<div class="code"><span class="code-lines"> 1</span>PROCEDURE global GET_ALL_MODELIDS lModelIDs:string nStartingPointForSearch:integer result:reference<br /><span class="code-lines"> 2</span>{<br /><span class="code-lines"> 3</span> CC "Documentation" GET_MODEL_GROUP_TREE_XML<br /><span class="code-lines"> 4</span> #--> RESULT ecode:intValue xml:strValue<br /><span class="code-lines"> 5</span> <br /><span class="code-lines"> 6</span> SETL nClosingRootTagPosition: (search(xml,"</root>",nStartingPointForSearch))<br /><span class="code-lines"> 7</span> WHILE (nStartingPointForSearch < nClosingRootTagPosition) {<br /><span class="code-lines"> 8</span> SETL nStartPositionOfGroupTag: (search(xml,"<model",nStartingPointForSearch))<br /><span class="code-lines"> 9</span> SETL nEndPositionOfGroupTag: (search(xml,">",nStartPositionOfGroupTag))<br /><span class="code-lines">10</span> SETL sModelID: (copy(xml,search(xml,"=",nStartPositionOfGroupTag) + 2,<br /><span class="code-lines">11</span> (search(xml,"name",nStartPositionOfGroupTag) - search(xml,"=",nStartPositionOfGroupTag)-4)))<br /><span class="code-lines">12</span> SETL nStartingPointForSearch: (nEndPositionOfGroupTag)<br /><span class="code-lines">13</span> <br /><span class="code-lines">14</span> IF (nStartingPointForSearch = -1) {<br /><span class="code-lines">15</span> BREAK<br /><span class="code-lines">16</span> }<br /><span class="code-lines">17</span> SETL lModelIDs: (lModelIDs + sModelID + " ")<br /><span class="code-lines">18</span> }<br /><span class="code-lines">19</span> SETL result: (lModelIDs)<br /><span class="code-lines">20</span>}<br /></div>Mateusz Dziedzic2017-12-07T12:00:14ZRE: Update attribute values at different elementsMateusz Dziedzichttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=10721252017-12-06T14:25:12Z2017-12-06T14:08:26ZRegarding1.:<br />The following code updates the value of the attribute “a3” for all objects of class “A” and its subclasses (within a model) whenever the value of “a3” is changed in an object of class “A”.<br /><br />1) Insert the following code to “Library attributes/Add-ons/Externalcoupling” in your dynamic library:<div class="code"><span class="code-lines"> 1</span>ON_EVENT"AfterEditAttributeValue"<br /><span class="code-lines"> 2</span>{<br /><span class="code-lines"> 3</span> SETsParams: ("")<br /><span class="code-lines"> 4</span> SETsParams: (sParams+ "SET nModelId: (" + ( STR modelid) + ")\n")<br /><span class="code-lines"> 5</span> SETsParams: (sParams+ "SET nInstId: (" + ( STR instid) + ")\n")<br /><span class="code-lines"> 6</span> SETsParams: (sParams+ "SET nAttrId: (" + ( STR attrid) + ")\n")<br /><span class="code-lines"> 7</span> SETsParams: (sParams+ "SET nAttrTypeId: (" + ( STR attrtypeid)+ ") \n")<br /><span class="code-lines"> 8</span> CC"AdoScript" FREAD file: ("%PathToFile%\\update.asc")<br /><span class="code-lines"> 9</span> #-->RESULT text:strValue ecode:intValue<br /><span class="code-lines">10</span> EXECUTE(sParams + text)<br /><span class="code-lines">11</span>}<br /></div><br />2) Insert the following code to the AdoScript file update.asc:<div class="code"><span class="code-lines"> 1</span>CC "Core" GET_CLASS_ID objid: (nInstId)<br /><span class="code-lines"> 2</span>#-->RESULT ecode:intValue classid:intValue<br /><span class="code-lines"> 3</span>SETL nClassID: (classid)<br /><span class="code-lines"> 4</span><br /><span class="code-lines"> 5</span>CC "Core" GET_CLASS_NAME classid: (nClassID)<br /><span class="code-lines"> 6</span>#-->RESULT ecode:intValue classname:strValue isrel:intValue<br /><span class="code-lines"> 7</span>SETL sClassName: (classname)<br /><span class="code-lines"> 8</span><br /><span class="code-lines"> 9</span>IF(sClassName = "A") {<br /><span class="code-lines">10</span> CC "Core" GET_ATTR_NAME attrid: (nAttrId)<br /><span class="code-lines">11</span> #-->RESULT ecode:intValue attrname:strValue<br /><span class="code-lines">12</span> SETL sAttrName: (attrname)<br /><span class="code-lines">13</span><br /><span class="code-lines">14</span> IF(sAttrName = "a3") {<br /><span class="code-lines">15</span> CC "Core" GET_ATTR_VAL objid: (nInstId) attrid: (nAttrId)<br /><span class="code-lines">16</span> #-->RESULT ecode:intValue val:anyValue<br /><span class="code-lines">17</span> SETL sAttrVal: (val)<br /><span class="code-lines">18</span> <br /><span class="code-lines">19</span> CC "Core" GET_ALL_OBJS_OF_CLASSNAME modelid: (nModelId) classname: (sClassName)<br /><span class="code-lines">20</span> #-->RESULT ecode:intValue objids:list<br /><span class="code-lines">21</span> SETL lObjids: (objids)<br /><span class="code-lines">22</span> <br /><span class="code-lines">23</span> FOR i from: (0) to: (tokcnt(lObjids)-1) {<br /><span class="code-lines">24</span> CC "Core" SET_ATTR_VAL objid: (VAL (token(lObjids,i))) attrname: (sAttrName) val: (sAttrVal)<br /><span class="code-lines">25</span> }<br /><span class="code-lines">26</span> }<br /><span class="code-lines">27</span>}<br /></div>Mateusz Dziedzic2017-12-06T14:08:26ZRE: Update attribute values at different elementsPascal Siboldhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=7327632016-12-12T10:49:40Z2016-12-12T10:43:50ZI managed to do it only on the the same element with the following code:<div class="code"><span class="code-lines"> 1</span>ON_EVENT "AfterEditAttributeValue" {<br /><span class="code-lines"> 2</span> CC "Core" GET_CLASS_ID objid:(instid)<br /><span class="code-lines"> 3</span> SETL nCurrentClassID:(classid)<br /><span class="code-lines"> 4</span> CC "Core" GET_CLASS_NAME classid:(nCurrentClassID)<br /><span class="code-lines"> 5</span> SETL sCurrentClassName:(classname)<br /><span class="code-lines"> 6</span> IF (sCurrentClassName = "KoGu") {<br /><span class="code-lines"> 7</span> CC "Core" GET_ATTR_NAME attrid:(attrid)<br /><span class="code-lines"> 8</span> SETL sAttrName:(attrname)<br /><span class="code-lines"> 9</span> IF (sAttrName = "First name") {<br /><span class="code-lines">10</span> CC "Core" GET_ATTR_VAL objid:(instid) attrid:(attrid)<br /><span class="code-lines">11</span> SETL sTypeValue:(val)<br /><span class="code-lines">12</span> CC "Core" SET_ATTR_VAL objid:(instid) attrname:("Last name") val:(val)<br /><span class="code-lines">13</span> }<br /><span class="code-lines">14</span> } <br /><span class="code-lines">15</span>}<br /></div><br /><br />Is there any solution to do it:<ol style="list-style: decimal inside;"><li>On another element?</li><li>On another element in another model?</li></ol>Pascal Sibold2016-12-12T10:43:50ZRE: Update attribute values at different elementsPascal Siboldhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=7284422016-12-05T13:36:40Z2016-12-05T13:36:40ZHello all<br /><br />Any solution for this? This is my main pain point at the moment.<br /><br />Thanks in advance and best regards,<br />PascalPascal Sibold2016-12-05T13:36:40ZRE: Update attribute values at different elementsPascal Siboldhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=7250452016-12-01T07:23:38Z2016-12-01T07:23:38ZI forgot to mention: the elements that need to be updated can be from/in different modeltypes.Pascal Sibold2016-12-01T07:23:38ZUpdate attribute values at different elementsPascal Siboldhttps://www.adoxx.org/live/c/message_boards/find_message?p_l_id=&messageId=7250312016-12-01T05:51:56Z2016-12-01T05:51:51ZHello<br /><br />In my language, there will be different specific document/data modelling elements of which each has a different set of attributes. However, there is some redundancy in the available attributes. So for example there are 3 modelling elements that have an attribute for the name of a person. In order to avoid, that the same data has to be entered for each attribute, whenever a user changes data, it shall be changed at all other elements where the same information is used.<br /><br />Is there any script or anything available to solve this?<br /><br />Thanks and best regards,<br />PascalPascal Sibold2016-12-01T05:51:51Z