on 04-08-2015 9:45 PM
Business Requirement:
Collection Field (REGION and COUNTRY) has below values:
EMEA Armenia
APAC China
Global blank
I have a requirement in the collection to find if the region value is "Global" to issue an error :
import com.sap.odp.api.doccommon.masterdata.*;
import com.sap.odp.api.ibean.common.AbsExtensionCollection.*;
import com.sap.odp.common.db.metadata.*;
geoCol = doc.getExtensionCollection("COLLGEOGRAPHY");
// New collection entries are captured in the below variables
if (!(geoCol.size() == 0)) {
geography = geoCol.get(0);
regionNew = geography.get("REGION");
countryNew = geography.get("GEOCOUNTRY");
}
set = new HashSet();
iter = geoCol.iterator();
while(iter.hasNext())
{
nextItem = iter.next();
region = nextItem.get("REGION");
country = nextItem.get("GEOCOUNTRY");
// If the region is blank mandate region
if(! (hasValue(region))) {
throw doc.createApplicationException("COLLGEOGRAPHY", "PROJERROR_REGION_BLANK");
}
// Error for duplicate countries
if (!set.add(country)) {
throw doc.createApplicationException("COLLGEOGRAPHY", "PROJERROR_REGION");
}
if ((regionNew.equals("Global"))) {
throw doc.createApplicationException("COLLGEOGRAPHY", "PROJERROR_COUNTRY_BLANK");
}
}
The last IF condition is not working in the above scenario how do I read a collection value?
Thanks,
Ramesh
Hello Ramesh,
I feel that this block is obsolete:
// New collection entries are captured in the below variables
if (!(geoCol.size() == 0)) {
geography = geoCol.get(0);
regionNew = geography.get("REGION");
countryNew = geography.get("GEOCOUNTRY");
}
If you are not purposely doing something with the *first* value of the collection you should remove it.
For the validation, you are doing everything correct, except you are checking 'regionNew', which will always have the first value of the collection.
To check all the values you have to replace the if with:
if ((region.equals("Global"))) {
Bogdan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.