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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Get Integer value and compare

jlittle
7-Bedrock

Get Integer value and compare

I have a need to view an integer from my ChangeRequest and make a decision based on the value. I have part of the code below, but do not know how to complete getting the value and then comparing it. The value comes from an Attribute (FinalCost) that is assigned to the ChangeRequest and is defined as an integer.

public static String getECRTotalCost(WTChangeRequest2 primaryBusinessObject)
throws WTException {
String result = ";
wt.change2.WTChangeRequest2 tc = (wt.change2.WTChangeRequest2) primaryBusinessObject;
wt.iba.value.IBAHolder ibaHolder = (wt.iba.value.IBAHolder)tc;
ibaHolder = wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer(ibaHolder, null, null, null);
wt.iba.value.DefaultAttributeContainer attributeContainer = (wt.iba.value.DefaultAttributeContainer)ibaHolder.getAttributeContainer();
wt.iba.definition.service.StandardIBADefinitionService defService = new wt.iba.definition.service.StandardIBADefinitionService();
wt.iba.definition.litedefinition.AttributeDefDefaultView attributeDefinition = defService.getAttributeDefDefaultViewByPath("FinalCost");
wt.iba.value.litevalue.AbstractValueView svc = attributeContainer.getAttributeValues(attributeDefinition)[0];
?????????????????????????????????????
if (svcint == (5000))
{result = "Low";}
else if (svcint >=(5000) && svcint <=(25000))
{result = "Med";}
else
{result = "High";}
return result;
}

any help would be appreciated.

Regards,

James Little

CAD Administrator

Corning Cable Systems

james.little@corning.com

1 REPLY 1
tbusch
1-Visitor
(To:jlittle)

Try this:
public static String getAttributeValue(IBAHolder object, String attributeName) {

try {
IBAHolder ibaHolder = IBAValueHelper.service.refreshAttributeContainer(object, null, null, null);

DefaultAttributeContainer attributeContainer = (DefaultAttributeContainer) ibaHolder.getAttributeContainer();
AttributeDefDefaultView attributeDefinition = IBADefinitionHelper.service.getAttributeDefDefaultViewByPath(attributeName);

AbstractValueView values[] = attributeContainer.getAttributeValues(attributeDefinition);

// This simply returns the 0th element if there are any at all.
for(int i = 0; i < values.length;) {
AbstractValueView value = values[i];
System.out.println("Value of " + attributeName + ": " + value.getLocalizedDisplayString());
return value.getLocalizedDisplayString();
}
} catch (IBADefinitionException e) {
e.printStackTrace();
} catch (NotAuthorizedException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (WTException e) {
e.printStackTrace();
}
return null;
}

You can then call this method like this:
int svcint = Integer.parseInt(getAttributeValue((IBAHolder)primaryBusinessObject, "myAttribute");
...

Yes, I know my error handling is lame 😉

-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<">mailto:tom.busch@stryker.com>
Announcements


Top Tags