Looping through the attributes in Java.

0
Hello everyone! I want to write a Java action, where I want to loop trough the attributes, I managed to get the keys, but I don’t know how can I get the decimal values. // BEGIN USER CODE //throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented"); IContext ctx = this.getContext(); ArrayList<IMendixObject> NewRatesCurrencyList = new ArrayList<IMendixObject>(); Map<String, ? extends IMendixObjectMember<?>> members = this.__RatesOld.getMembers(this.getContext()); Set<String> mapping = members.keySet(); for(String key : mapping) { IMendixObjectMember<?> member = members.get(key); if( member instanceof com.mendix.core.objectmanagement.member.MendixObjectReference ) { } else if( member instanceof com.mendix.core.objectmanagement.member.MendixObjectReferenceSet ) { } else{ RatesCurrency NewRatesCurrency = new RatesCurrency(ctx); NewRatesCurrency.setNameCode(key); // Here I want to get the Value by the key // for example like this, but looping trought the keys // in this example the key is HUF BigDecimal valBD2 = this.RatesOld.getHUF(RatesOld.getContext()); NewRatesCurrency.setValue(this.RatesOld.getContext(),valBD2); NewRatesCurrencyList.add(NewRatesCurrency.getMendixObject()); } } return NewRatesCurrencyList; // END USER CODE  
asked
2 answers
1

Hi Marcell,

It kind of depends on what you want to do. I’d start by iterating over the IMendixObjectMembers like so:

for(IMendixObjectMember objectMember : members) {
String stringValue = RatesOld.getValue(ctx, objectMember.getName());
}

Then you have a StringValue representation of the current object member.

If you want the decimal value, you could check if the objectMember is a type of MendixDecimal. Since it is a subclass of IMendixObjectMember, you can check if the objectMember is a MendixDecimal. If so, then you should be able to do

BigDecimal decimalValue = RatesOld.getValue(ctx, objectMember.getName());

Not sure about the exact syntax, so let me know if this is enough to work it out and do report back with the result if you can 👍

answered
0

Hi Marcell,

 

You can parse the value by simply using

 

double val = Double.parseDouble(this.RatesOld.getHUF(RatesOld.getContext()));

 

To set the value you can simply say 

 

NewRatesCurrency.setValue(this.RatesOld.getContext(),Double.toString(val));

It’s been a while since I last did it, but this should get you on the right track ;)

answered