Hi all,
I've tried to set the value of an attribute of the type enumerator in a macro.
I tried the methods
Designer.setAttribute(myModel, myObj,Constants.AT_SAP_FUNC_TYPE, "Process", null) and Designer.setAttributePersistent(myObj, Constants.AT_SAP_FUNC_TYPE, "Project", null)The result was that in the first case, although no error was thrown, the attribute value remained unchanged. In the second case an error was thrown stating that an parameter of type String was passed instead of Integer. This error message doesn't make much sense: When I tried exactly the same statement with the attrTypeNum "AT_SHORT_DESC", it worked flawlessly.
When I try to do the same in a report by the following statement, the attribute is set without any problems:
ObjDef.Attribute(Constants.AT_SAP_FUNC_TYPE, Context.getSelectedLanguage).setValue("Process")Does anyone know whether there's a different way to set the value of enumerator attributes in a macro? Or has someone experienced a similar problem?
Thank you and best regards,
Philipp
Hello Philipp,
I am afraid, the error message "string instead of integer" is right, but it refers to the rather hidden explanation in Aris Script Help: search for AT_SAP_FUNC_TYPE leads to the topic "Constants from AttrTypeTblNum". For an attribute of the type enumerator the list of allowed values consists again of numeric constants (attribute value types AVT_*), whereas you tried to set the attribute value to the strings "Process" or "Project".
For your purpose you should use AVT_PROC_1 (Process) or AVT_SOLAR_PROJECT (Project) resp. in macros.
Perhaps this holds strictly only for macros as Aris Script Help states for the setValue() method in report scripting (s. Help topic "Report class Attr - Method setValue") a more lax usage of strings instead of constants for numeric attribute value types.
"AT_SHORT_DESC" worked all right, because it is a string attribute.
Hope this helps, Martin
Hi,
Have you tried the delete-function?
modelVAC.Attribute(Constants.AT_SAP_MOD_TYPE, [LOCALE]).Delete()
In general: If you set the the value of an attribute to an empty string, it's still considered as maintained. So if you run searches, this can be an issue.
I hope this helps you solving the problem.
Hello All,
eleven years later I have found this thread and I think that it would be good to extend it. What Martin has demonstrated is how to set the Built-in Attribute Value Type using Macro. Maybe it is obvious, but for Custom = User Defined Attribute Value types, you can use following approach.
I use this code to set certain custom attributes to default values when new object occurence is dropped to the model.
var oNewObjOcc = Context.getSelectedObjOccs()[0];
var oModel = Designer.getModel(oNewObjOcc);
// Get Current Object Occurence and then Model in which we are dropping that occurence
var oNewObj = Context.getSelectedObjects()[0];
// Get Object definition object to which the dropped Occurence belongs to
var metamodel = Context.getArisMethod();
// Attributes and Attribute values are defined in ARIS method, not in the DB or any actual model. var metamodel is defined to access that info
var intAttRef = metamodel.UserDefinedAttributeTypeNum("00000000-0000-0000-0000-000000000000");
// As you will read around this forum, it is better to work with GUIDs as they can be moved between servers. Find it for your custom Attribute Type in Administration/Configuration/Method/Attribute Types/API Name, this will return Type Number integer
var intAttValRef = metamodel.UserDefinedAttributeValueTypeNum("00000000-0000-0000-0000-000000000000","11111111-1111-1111-1111-111111111111");
// Similar approach for Attribute Value, you just need GUID of Attribute Type same as above, and GUID of Attribute Type Value. Get it from Edit Attribute Type/Values and symbols/GUID for each defined value.
Designer.setAttributes(oModel,oNewObj,intAttRef, intAttValRef, null);
// with all this prepared you can finally set the value, note that I am not bothering with Language param, null = DB language
I have spent nice 3 days trying to figure out how to set custom attribute values that don't have built-in Constants via Macro and was mislead by the documentation Macro Class Designer - Method setAttribute that says: int--attrTypeNum and Object--value, where it actually should be understood as that both 2nd and 3rd parameters are actually integers when using custom attributes.
Hope it helps somebody.