Hey guys,
i want to create a dialog, where the user can select an object (Context.BrowseArisItems(...)) to edit the attributes of the selected object.
The problem is, that some objects have attributes which are language dependent.
E.g. the name of the object can be in "en_US" and in "de_DE".
When I use this code:
var userObject = Context.BrowseArisItems("Select an object", "Select an object to edit the attributes.", Constants.CID_OBJDEF)
var oSelectedObject = userObject[0]; //Selected User Object
var objectTypeName = Designer.getAttribute(oSelectedObject,389,null)
I get just the attribute in the database language (en_US or de_DE), but I need the attribute in "en_US" and in "de_DE".
How I can get the attributes in de and in en_US?
Basically what you want to do is replace the null in your Designer.getAttribute call with an object of the type Language. Sounds simple, doesn't it? Well it isn't. Here is an example of what I came up with (Macro context: only object definitions of type Org Unit, it should work with other object definitions (like the ones you picked with your BrowseArisItems() method) too).
var p_selObjDef = Context.getSelectedObjects(); //Get the selected Object Definitions main(); //Just a habit of mine, don't want to clutter the global namespace function main(){ //see previous point for each (var selObjDef in p_selObjDef){ //for each selected Object definition var languageGerman = getLanguageWithLocale(selObjDef, java.util.Locale.GERMANY); //calls a self built opposite method of Designer.toLocale(language), that transforms a field of java.util.Locale back into an ARIS Object of the type Language var languageUS = getLanguageWithLocale(selObjDef, java.util.Locale.US); //see previous point if((languageGerman != null) && (languageUS != null)){ //if both Language objects are available now Context.MsgBox("German name attribute: " + Designer.getAttribute(selObjDef, Constants.AT_NAME, languageGerman).getPlainText() + "\nEnglish name attribute: " + Designer.getAttribute(selObjDef, Constants.AT_NAME, languageUS).getPlainText()); //Open a dialog with some data to show that it works } } //This is where the fun begins function getLanguageWithLocale(selObjDef, localeField){ //A method that can use an object definition (or anything else that has ties to the login, only tested it with object defs though) and a field of java.util.Locale, to find an ARIS Object of the type Language var loginInfo = Context.getLoginInfo(selObjDef); //Get information about the current login var curDatabase = loginInfo.getDatabase(); //get the database the user is currently logged into var allLanguages = Designer.getAllDBLanguages(curDatabase); //get all available languages for this database for each (var oneLanguage in allLanguages){ //iterate through all allowed Languages var localeLanguage = Designer.toLocale(oneLanguage); //Transform the language into an java.util.Locale object, for comparisons sake if(localeLanguage.equals(localeField)){ //if the locale we are currently viewing matches the one we gave the method through the field return oneLanguage; //return the Language object from which we obtained the Locale object } } return null; //if you can't find any matching Language, return null to make this noticeable } }
If you have any additional questions, need more clarification/explanation, or are just confused af, feel free to reply. I'll see what I can do.
Oh and the fields of java.util.Locale, should you want to use other languages, can be found here https://docs.oracle.com/javase/7/docs/api/java/util/Locale.html#field_summary in the field summary for example.
Edit: made java.util.Locale field summary link jump directly to the field summary
Thank You Kai. It was very help full. And you are right, it isn´t simple.
My solution is a little bit different: (I think it is the same).
(...)
var attr = Designer.getAttributes(oSelectedObject,null);
oName = findAttr(1,attr,"en_US"); //1 is the attribute type number for the object name, you can use any attribute type number
function findAttr(attrType,attr,attrLanguage){
var ergebnis = [];
for(var i = 0; i<attr.length;i++){
if(attr[i].getAttrType() == attrType){
var attrLocale = Designer.toLocale(attr[i].getLanguage());
var arr = [attr[i],attrLocale];
ergebnis.push(arr);
}
}
for(var j = 0;j<ergebnis.length;j++){
if(ergebnis[j][1] == attrLanguage){
return ergebnis[j][0];
}
}
return "";
}
(...)