cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

WC 10.1 Retrieving values from a multi-valued IBA?

sdrzewiczewski
7-Bedrock

WC 10.1 Retrieving values from a multi-valued IBA?

I'm trying to grab the value from some IBAs using the newcom.ptc.core.lwc.server.LWCNormalizedObjectclass.


For values that are single valued, i'm having no problems, but when i have mult-valued IBAs I'm stuck. The get method says it's supported, but for the life of me I can't figure out how to access them. It sounds like an array of Objects will be returned.


If anybody has used this class for retrieving a multi-valued IBA and would share the code snippet, I would appreciate it.




get

public Object get(Stringattribute)
throws WTException

 <dd>

Supported API: true
Returns the value(s) of the attribute with the given name from the object. If the attribute is multi-valued, an Object[] will be returned. Throws an exception if the attribute has not been previously loaded into the object.</dd>



2 REPLIES 2

Steve,

Here's a snippet that works and may get what you need:

LWCNormalizedObject lno = new LWCNormalizedObject(pdpPart, null, null, null);
lno.load(designFunc);
Object designFuncValue = lno.get(designFunc);

if (designFuncValue instanceof Object[]) {
logger.debug(CLASSNAME + ".getSupplementalRoles(): instanceof Object[]");
Object[] designFuncValues = (Object[])designFuncValue;
for (int i = 0; i < designFuncValues.length; i++) {
if (((String)designFuncValues[i]).equals(mech)) {
roles.add(Role.toRole(mechRole));
} else if (((String)designFuncValues[i]).equals(elec)) {
roles.add(Role.toRole(elecRole));
} else if (((String)designFuncValues[i]).equals(opt)) {
roles.add(Role.toRole(optRole));
} else if (((String)designFuncValues[i]).equals(sw)) {
roles.add(Role.toRole(swRole));
}
}
} else {
logger.debug(CLASSNAME + ".getSupplementalRoles(): not instanceof Object[]");
if (((String)designFuncValue).equals(mech)) {
roles.add(Role.toRole(mechRole));
} else if (((String)designFuncValue).equals(elec)) {
roles.add(Role.toRole(elecRole));
} else if (((String)designFuncValue).equals(opt)) {
roles.add(Role.toRole(optRole));
} else if (((String)designFuncValue).equals(sw)) {
roles.add(Role.toRole(swRole));
}
}

Thanks,
Jason Schrader

Thanks that was just what I needed! I wasn't casting the object to an array of objects correctly.

Steve D.
Top Tags