I have created an attribute called "serial Number" to contain a birth certificate for our function objects and models derived from the GUID.
For new objects and models this works fine - by running a macro.
(Models - on model creation)
(Objects - on model close) - always check and update function objects
The User defined attribute being populated is set to read-only.
Upon running a script to backfill all existing models and objects - the models update fine. The problem is the objects don't! The resulting message tells me that it cannot update object attributes set to read-only. Que?
So it's one rule for models, another entirely for objects? Can anyone shed any light on this?
Is there a way of checking to see if the attribute is read-only, set to editable, then set back once updated?
Here's my script:
// global variables var nLoc = Context.getSelectedLanguage() function main(){ var oSelectedGroups = ArisData.getSelectedGroups() var db = ArisData.getActiveDatabase(); var filter=db.ActiveFilter(); var udSerialNumber = filter.UserDefinedAttributeTypeNum("1a8f5810-6496-11e2-0c7e-005056950062"); if(oSelectedGroups.length>0){ // var dlgResult = Dialogs.MsgBox(getString("S_INC_SUBGGROUPS"), Constants.MSGBOX_ICON_QUESTION | Constants.MSGBOX_BTN_YESNO, getString("S_INC_SUBGGROUPS_HDR")); var bRecursive = true //(dlgResult == Constants.MSGBOX_RESULT_YES); var oSelectedGroupCount = oSelectedGroups.length; // for (var i = 0; i < oSelectedGroups.length; i++) { // oSelectedGroups = oSelectedGroups.concat(oSelectedGroups[i].Childs(bRecursive)); // } // models in group are > 1 for(var c2=0;c2<oSelectedGroups.length;c2++) // loop through the models in the group performing the action { var oObj = oSelectedGroups[c2].ObjDefList(true, [Constants.OT_FUNC]); oOutCount = 0 oOutput.OutputLn("------------------------------" , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn(" " , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("Group Name:" + oSelectedGroups[c2].Name(nLoc), "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("Group Path:" + oSelectedGroups[c2].Path(nLoc), "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn(" " , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); if (oObj.length>0){ for(var i2=0; i2<oObj.length; i2++){ var objName = oObj[i2].Name(nLoc); var objType = oObj[i2].Type(); if (objType=='Function'){ var existSerialNumber = getAttributeValue(oObj[i2], udSerialNumber); // existing Identifier var mod_guid = oObj[i2].GUID(); var NewID= stripGUID(mod_guid); // GUID if (Left(mod_guid,18) != existSerialNumber || existSerialNumber == '') { // update the attribute //setAttributeValue(oSelectedModels[c2], udSerialNumber,NewID) oObj[i2].Attribute(udSerialNumber,nLoc).setValue(NewID) oOutput.OutputLn("Object: " + objName + " | Updated with Serial Number:" + NewID + "|", "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutCount++; gOutCount++; } oOutFoundCount++; } } } if (oOutCount==0){ oOutput.OutputLn("------------------------------" , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("No Functions Objects to Update" , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); } else { oOutput.OutputLn("------------------------------" , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("Objects Found:" + oOutFoundCount , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("Objects Updated:" + oOutCount , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); } } oOutput.OutputLn("------------------------------" , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("Total Objects Updated:" + gOutCount , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.OutputLn("------------------------------" , "Arial", 10, Constants.C_BLACK, Constants.C_TRANSPARENT, Constants.FMT_LEFT, 10); oOutput.WriteReport(); } } // end main
Any ideas anyone?