Hello Community!
Do you guys know how can I get attribute values of a model and objects using a script?
I want to get the value of an attribute that I've created - How can I do that?
Thanks in advance!
Regards,
Dilcarina
Hello Community!
Do you guys know how can I get attribute values of a model and objects using a script?
I want to get the value of an attribute that I've created - How can I do that?
Thanks in advance!
Regards,
Dilcarina
I got it:
var num = Context.getSelectedLanguage();
function getAttrStrValue(objectDef, p_attrTypeNum, num){
var attr = objectDef.Attribute(p_attrTypeNum, num, true);
if(attr.IsValid() == false) return gs_Empty;
return Packages.java.lang.String( attr.GetValue(true) );
}
To find the attribute type numbers: Aris Architect > Administration > Configuration > Method > Attribute types
Regards,
Dilcarina
Just adding information here about how to get the attribute type number, instead of hard-coding it into your script (no objections with how you use the number within the Attributes(...) method):
I'd recommend that you use the API Name, instead of the type number. It makes scripts much easier to read and understand. Additionally the API name will never change, while you can't be quite sure about that with the type number. You can use the API name by using
Constants.API_NAME
Example: For me the "Description/Definition" attribute has the attribute type number 9 and the API name AT_DESC.
Whenever I use
Constants.AT_DESC
directly within my script, the computer can look up the type number and replace the part that says Constants.AT_DESC with the integer 9 when the script is run.
You can find the API name in the column next to the type number column, which you already found in "Architect" > "Administration" > "Configuration" > "Method" > "Attribute types".
To look up the API name of attributes from within the "Attributes" window of object definitions and models, you can select the cell into which you would usually type the attribute value, and hit Ctrl+F1 to open the help page for the given attribute.
When you create custom attributes (attributes that aren't ARIS standard), the column "Type number" in "Architect" > "Administration" > "Configuration" > "Method" > "Attribute types" will show you a GUID of the attribute, instead of an attribute type number (easily distinguishable - type numbers are decimal and short, GUIDs are much longer, are hexadecimal and usually contain dashes). You can not use "Constants." with those. Instead there is a programmatic way to look up the type number for the GUID API Name.
ArisData.ActiveFilter().UserDefinedAttributeTypeNum("GUID_GOES_HERE");
Example: Imagine there is a custom attribute "Requirements", with the type number 265917 and the the API name column says 4329b3e3-2a44-33b0-1ea5-d8df42cdfc1b.
At the beginning of the script I would add the following line:
var AttrTypeNumRequirements = ArisData.ActiveFilter().UserDefinedAttributeTypeNum("4329b3e3-2a44-33b0-1ea5-d8df42cdfc1b");
This makes the computer look up the attribute type number a single time, and whenever I want to use it within the script, I just have to use the value assigned to AttrTypeNumRequirements.