Hello,
a customer asked us to disable the editing of object attributes by users, so I created a macro with "Object attribute is to be changed by modeling (vetoable)". The macro disabled all object attributes, but the customer wanted to disable only a subset of them.
Is it possible?
Thanks
Tatiana Piomboni
You can create attributes as not being editable by users. You can access and modify them via script only then. When you create the Attribute type you have to clear the check mark "Editable". It's not possible to change that after creation of the attribute type. So for existing attribute types there is no such possibility. Either the user has write permissions to the object or he hasn't.
Hi,
that's totally possible.
You'll have to decide for a whitelist or blacklist strategy (either you forbid by default all attributes to be edited and only allow a subset of attributes to be edited (whitelist) or your allow by default all attributes to be edited and only forbid a subset of attributes to be edited (blacklist))
Either way, what you need in your Macro is an array with all the attribute type numbers either of the attributes which you allow to be edited, or which you forbid to be edited.
For standard attributes you can just use Constants.AT_... (the API name which you can find in your ARIS method configuration). For custom attributes I highly recommend you retrieve the attribute type number with Context.getARISMethod().UserDefinedAttributeTypeNum("here goes the GUID which you can find in the ARIS method configuration")
Once you've got this whitelist or blacklist array, you just have to add a bit more logic to your main program that flips the macro property value event.veto from the default 0 to 1 (event.veto is how you already veto your attribute editing, right?)
It goes a little bit like this (demonstrating the blacklist strategy)
var currentlyAttemptedToEditAttrTypeNr = Context.getProperty("event.arguments").getValue("attribute_type_num") var shouldVeto = false; for each(var sigleForbiddenAttrTypeNum in blacklistArray) { if(currentlyAttemptedToEditAttrTypeNr == sigleForbiddenAttrTypeNum) { shouldVeto = true } } if (shouldVeto) { Context.setProperty("event.veto", "1") }
Further note: you could probably significantly speed up the lookup of attribute type numbers, if you store them in a Javascript Map instead of a Javascript Array. Then you wouldn't have to iterate through your array checking every value, instead you would just ask the map for the value associated with your currentlyAttemptedToEditAttrTypeNr and it either returns something like an empty string if it's registerd in the map or null if it's not registerd in the map.
But I'm not too familiar with Javascript maps, so I can't tell you exactly how to do it.
Thank you very much Kay.
I tested your solution and it works.
I didn't know the key "event.arguments" for Context.getProperty.
In the ARIS Script online help I found this:
"event".
"event.id".
"event.component".
"event.veto".
Is there more documentation about this?
Thanks a lot
Tatiana Piomboni
Hi Tatiana,
all I knew was that it is possible (cuz of course it is, otherwise I'd have to create a dust collecting feature request using ARIS Empower and that wouldn't be fun), but I didn't find it directly through the online script help either.
The way I found it was
- List all properties with Context.getProperties(). The thing that caught my eye was the "event.arguments" property (simply because it sounded like something related to your question).
- Retrieved "event.arguemnts" property with Context.getProperty(...). While debugging the debugger told me that this property has not just a simple primitive data type as a value, but it actually corrosponds to an object of a class you can find in your online script help: MacroEventArguments (ARIS Script > Methods for macros and transformations > Objects > MacroEventArguments).
- MacroEventArguments has a method called .getKeys(). I used that to find the String "attribute_type_num", which I could plug into the .getValue(...) method of MacroEventArguments to get the thing you were looking for.
I actually gave up on the thought of the online script help being comprehensive a while ago. If you really want to learn what you can do with ARIS Script you have to use it, write programs/test scripts, try things and work your own dev skills (the difference between using 90% of ARIS Script an using 99% of ARIS Script). The online script help certainly helps to an incredibly great degree, but if you want to get the absolute most out of ARIS script, just play around with it until you find what you need. The debugger and breakpoints are an absolute necessity for this act too.