Hello,
I was wondering if there was any built in function or macro in ARIS that will automatically check to see if an object occures in multiple models, and if so, warn the modeller before they change the name of the object. This way, it'll prevent them from having to go through the properties and also help prevent accidental name changes.
I've dug around the macros and there is an event on "object name change (persistant)" but this only checks it after it's been saved. Similarly, on the object attributes change (vetoable), it checks prior to the name being changed.
What I am looking to do is have the following occur:
1) User clicks to do a name change
2) User changes name
3) User clicks out so name applies
4) Macro runs to validate if this object occures in multiple locations
a) if it does, then give pop up warning asking if they are sure they want to change it because it will impact other models. If they hit okay, it keeps change. If they hit cancel, it reverts back to origional name
b) If it doesn't, just change name
Thanks,
David
David Tse Author on
I wasn't able to get what I was looking since I don't believe there is any way to validate after an object's name is changed but before it is saved (only on the click or on save). I created the macro to check "on save" and I created a new attribute called "previousName" that stores the most recent name in case people decide not to revert the changes.
This is how to code works:
Here is a sample of the warning:
Here is the MACRO code (NOTE: Because previousName is a custom made attribute, you need to change the previousName GUID to what yours is)
var selModels = Context.getSelectedModels(); var nLocale = Context.getSelectedLanguage(); var selobjs = Context.getSelectedObjects(); var CONSTANT_PREVNAME = 68838; for (var i=0;i<selobjs.length;i++) { var occ = Designer.getOccs(selobjs[i]); var occModels = []; //this stores the model GUID so we know if we've seen it before //for every occurance of this object, we need to see which model it is in for (var y=0;y<occ.length;y++) { var found = false; var oModel = Designer.getModel(occ[y]); for (var x=0;x<occModels.length;x++) { if (occModels[x] == Designer.getGUID(oModel)) found = true; } if (!found) occModels.push(Designer.getGUID(oModel)); } //We now know how many models this object occures in. If it's in more than one //that we need to indicate that. var objType = Designer.getAttribute(selobjs[i], 389, null); var previousName = Designer.getAttribute(selobjs[i], CONSTANT_PREVNAME, null); var currentName = Designer.getAttribute(selobjs[i], Constants.AT_NAME, null); //We only run this if it shows up in more than one model if (occModels.length > 1) { var btnPressed = Dialogs.MsgBox("You are about to change a(n) " +objType+ "'s name to \""+currentName +"\". This object occures in " + (occModels.length - 1) + " other model(s).\nAre you sure you want to continue?", "Warning", Constants.MSGBOX_ICON_WARNING, Constants.MSGBOX_BTN_OKCANCEL); switch (btnPressed) { case Constants.MSGBOX_RESULT_OK: //We set the previousName to current one Designer.setAttributePersistent(selobjs[i],CONSTANT_PREVNAME,currentName,null); break; case Constants.MSGBOX_RESULT_CANCEL: Designer.setAttributePersistent(selobjs[i],Constants.AT_NAME,previousName,null); break; default: Dialogs.MsgBox("How did you click something else?"); } } else { //This means that it only shows up in one model. This might mean it's a new object or just shows up once //either way, we need to set it's prevname to it's current name Designer.setAttributePersistent(selobjs[i],CONSTANT_PREVNAME,currentName,null); } }You will probably need to run a script to auto update all your objects with the previousName attribute set to the current name. Here is a REPORT that will do it. Once again, you need to change the GUID of the previousName attribute!
var oSelGroups = ArisData.getSelectedGroups(); var nLocale = Context.getSelectedLanguage(); // Selected database language for (var n = 0; n < oSelGroups.length;n++) { var objectsList = oSelGroups[n].ObjDefList(true); for (var i = 0; i < objectsList.length; i++) { var object = objectsList[i]; // Current model var objectName = object.Name(nLocale); // Name of current model var attr = object.Attribute(68838, nLocale); //CHANGE THAT NUMBER TO YOUR ATTRIBUTE NUMBER attr.setValue(objectName); } }