RB

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?

 

 

by Kay Fischbach
Posted on Fri, 07/20/2018 - 13:17

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

0
by Rene Broll Author
Posted on Mon, 07/23/2018 - 08:07

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 "";            

     }

 

(...)

 

 

 

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock