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
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:
- User modifies an object and hits save
- Macro auto runs on object name change
- Determines if the object occures in multiple models
- If it shows up in more than one (aka other than the current model), it will pop open a message warning the user that they are about to impact more than their own model
- If they hit "Ok", it saves the previousName to the current name and ARIS does the rest
- If they hit "Cancel," it resets the current name to the previousName
- If the change only exists in one model, it will auto save the previousName to the current name
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); } }
Hi David,
One small suggestion from my side. You should use the GUID of the user defined attribute rather than the type number. Restart of the business server can, under some conditions cause the type number to change. This is most certainly so for an upgrade of the business server. The GUID on the other hand is stable and doesn't tend to change.
If you change the declaration like below:
// var CONSTANT_PREVNAME = 68838 var CONSTANT_PREVNAME = Context.getArisMethod().UserDefinedAttributeTypeNum("GUID of the attribute");
This change should make your macro more sustainable and upgrade proof.
Best regards,
Edwin