Skip to main content
1-Visitor
Nov 10, 2011 10:30 AM UTC
Solved

Retrieving a Attribute from an Object Using an Expression in a Workflow

Hi All,

I need to retrieve an attribute ("Operation") which which I have added to a Change Notice in a workflow expression - since the value of this attribute alters downstream activities.

So far I have got as far as:

wt.change2.WTChangeOrder2 co = (wt.change2.WTChangeOrder2)primaryBusinessObject;

String coOperation = ...

Also by using the above code, does it matter that I want to retrieve the attribute from a soft type of the change notice.

Any help would be great.

Toby

dsolatAnswer
1-Visitor
May 22, 2012 9:18 AM UTC

You can try the code below as it works fine -

wt.change2.WTChangeOrder2 cm1 = (wt.change2.WTChangeOrder2) primaryBusinessObject;

wt.iba.value.IBAHolder ibaHolder1 = (wt.iba.value.IBAHolder)cm1;

ibaHolder1 =wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer(ibaHolder1, null, null, null);

wt.iba.value.DefaultAttributeContainer attributeContainer =(wt.iba.value.DefaultAttributeContainer) ibaHolder1.getAttributeContainer();

wt.iba.definition.service.StandardIBADefinitionService defService = new wt.iba.definition.service.StandardIBADefinitionService();

wt.iba.definition.litedefinition.AttributeDefDefaultView attributeDefinition = defService.getAttributeDefDefaultViewByPath("PhoneNumber"); //Here give the attribute name instead of "PhoneNumber".

wt.iba.value.litevalue.AbstractValueView svc = attributeContainer.getAttributeValues(attributeDefinition)[0];

IBAValue_PhoneNumber = svc.getLocalizedDisplayString();

24 replies

1-Visitor
Nov 10, 2011 5:57 PM UTC

It would help to learn the wt.query and wt.fc packages. Short of that, just use info engine.

public static Group test(WTObject primaryBusinessObject) throws Exception {

String instance = WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName");

IeService service = new IeService();

ObjectWebject webject = new ObjectWebject("QUERY-OBJECTS");

webject.setService(service);

webject.setParam("INSTANCE",instance);

webject.setParam("OBJECT_REF",PersistenceHelper.getObjectIdentifier(primaryBusinessObject).getStringValue());

webject.setParam("ATTRIBUTES","*");

webject.invoke();

Group group = webject.getService().getGroup();

return group;

}

group.getAttributeValue(0, "Operation");

p.s. Don't hardcode this inside an expression. And it has to run on the MethodServer. Your servlet engine won't like it.

Translate
22-Sapphire I
Nov 10, 2011 6:19 PM UTC

We do this very often in many workflow templates, without using webjects - just need simple Java code.


But - In 10.0, check out the new GUI-based way to do this that is available - very nice.

Translate
22-Sapphire I
Nov 10, 2011 6:21 PM UTC

We do this very often in many workflow templates, without using webjects - just need simple Java code.


But - In 10.0, check out the new GUI-based way to do this that is available - very nice.

Translate
1-Visitor
Nov 16, 2011 1:53 PM UTC

Hi Mike,

Currently we are only on 9.1 (need a proE upgrade first), so will not be getting 10.0 for about another year. So if you can do it in a workflow then can you please tell me the java expression I need? Or at least where precisely I should be looking.

Also, is the Windchill Javadoc the only means of learning the packages as Matthew has suggested I do?

Regards,

Toby

Translate
1-Visitor
Nov 16, 2011 4:42 PM UTC

I know of two other ways to retrieve IBA values.

1. Would be to write your own queryspec, joining your pbo to the *value table, and joining that to the *definition table.

2. Uses your pbo's AttributeContainer, and retrieves the AttributeDefDefaultViews and AbstractValueViews.

1 is the approach we use when writing reports. 2 is the approach we use when dealing with single objects where we want to get/set values, but involves lots of code.

Mike, can you share your method?

Toby, you're kind of in a tough spot if you don't have an expert on hand. When I'm trying to figure something new out, I'll usually start with looking into how PTC does it. Knowing how they structure their packages and name their classes helps.

If you were doing something with documents, you may start by looking in the wt.doc package. There you'd find wt.doc.WTDocumentHelper.

If you were doing something with parts, you may start by looking in the wt.part package. There you'd find wt.part.WTPartHelper

If you were doing something with access control, you may start by looking in the wt.access package. There you'd find wt.access.AccessControlHelper

Beyond that, "helpers" often have "managers" or "services." So you could end up with WTDocumentHelper.service.* etc

Translate
1-Visitor
Nov 17, 2011 12:00 PM UTC

I found this on another post (http://communities.ptc.com/message/165328😞

wt.fc.QueryResult qr = null;

wt.doc.WTDocument RCIDFDoc=((wt.doc.WTDocument)primaryBusinessObject);

ext.generic.util.IBAUtil objHelper = new

ext.generic.util.IBAUtil(RCIDFDoc);

ApplicationNum=objHelper.getIBAValue("ApplicationNum");

BusinessCategory=objHelper.getIBAValue("BusinessCategory");

EstimatedNetSales=objHelper.getIBAValue("EstimatedNetSales");

FGNum=objHelper.getIBAValue("FGNum");

I tweaked this to the following:

result = "NAY";

wt.fc.QueryResult qr = null;

wt.change2.WTChangeOrder2 co =((wt.change2.WTChangeOrder2)primaryBusinessObject);

ext.generic.util.IBAUtil objHelper = new ext.generic.util.IBAUtil(co);

String selectedOption=objHelper.getIBAValue("UpdateJobs");

if (selectedOption.equals("No")) {

result = "YAY";

}

It came up with no errors when I first compiled it, I tested it, it failed, now when I compile it it comes up with the following error:

Checking Syntax...

/apps/ptc/Windchill_9.1/Windchill/tmp/WfExpression8906920.java:39: package ext.generic.util does not exist

ext.generic.util.IBAUtil objHelper = new ext.generic.util.IBAUtil(co);

^

/apps/ptc/Windchill_9.1/Windchill/tmp/WfExpression8906920.java:39: package ext.generic.util does not exist

ext.generic.util.IBAUtil objHelper = new ext.generic.util.IBAUtil(co);

^

2 errors

Syntax check complete.

It give anyone any ideas?

Translate
1-Visitor
Nov 17, 2011 4:06 PM UTC

ext.generic.util.IBAUtil was something custom they created. It's not OOTB, as far as I know

Translate
1-Visitor
Nov 17, 2011 4:08 PM UTC

I think you are right, I have seen that kind of thing referenced a number of times and it definitely is not a package in our system.

Translate
dsolat1-VisitorAnswer
1-Visitor
May 22, 2012 9:18 AM UTC

You can try the code below as it works fine -

wt.change2.WTChangeOrder2 cm1 = (wt.change2.WTChangeOrder2) primaryBusinessObject;

wt.iba.value.IBAHolder ibaHolder1 = (wt.iba.value.IBAHolder)cm1;

ibaHolder1 =wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer(ibaHolder1, null, null, null);

wt.iba.value.DefaultAttributeContainer attributeContainer =(wt.iba.value.DefaultAttributeContainer) ibaHolder1.getAttributeContainer();

wt.iba.definition.service.StandardIBADefinitionService defService = new wt.iba.definition.service.StandardIBADefinitionService();

wt.iba.definition.litedefinition.AttributeDefDefaultView attributeDefinition = defService.getAttributeDefDefaultViewByPath("PhoneNumber"); //Here give the attribute name instead of "PhoneNumber".

wt.iba.value.litevalue.AbstractValueView svc = attributeContainer.getAttributeValues(attributeDefinition)[0];

IBAValue_PhoneNumber = svc.getLocalizedDisplayString();

Translate
1-Visitor
May 23, 2012 9:12 AM UTC

Apologies I thought it did not work, I got an error but I think I may have made a mistake with the attribute logicID.

It is now working, thankyou!

Regards,

Toby

Translate
17-Peridot
May 23, 2012 6:25 PM UTC

If you are using 10.0 there are much simpler programmatic methods for getting and setting of IBA values -

More info can be found in the javadoc - com.ptc.core.lwc.server.LWCNormalizedObject

Here are some examples

Example usage:

CREATE

LWCNormalizedObject obj = new LWCNormalizedObject("com.acme.AcmePart",null,null);

obj.load("name","number");

obj.set("name","my name");

obj.set("number","12345");

obj.persist();

RETRIEVE

LWCNormalizedObject obj = new LWCNormalizedObject(my_persistable,null,null,null);

obj.load("name","number");

Object nameValue = obj.get("name");

Object numberValue = obj.get("number");

UPDATE

LWCNormalizedObject obj = new LWCNormalizedObject(my_persistable,null,Locale.US,new UpdateOperationIdentifier());

obj.load("attributeA","attribtueB");

obj.set("attributeA",new Boolean(true));

obj.set("attribtueB","PURPLE");

obj.apply();

...

PersistenceHelper.manager.modify(my_persistable);

Translate
1-Visitor
May 24, 2012 9:25 AM UTC

Thanks Jeffrey, unfortunately we are stuck with 9.1 for the short-mid term. I will most likely move to this cleaner approach when we do move to 10 though.

Regards,

Toby

Translate
1-Visitor
Feb 10, 2015 8:25 PM UTC

getting this error when checking syntax

Checking Syntax...

C:\ptc\Windchill_10.2\Windchill\temp\WfExpression831571.java:39: error: cannot find symbol

IBAValue_VM_Name= VM_Name

^

symbol: variable IBAValue_VM_Name

location: class WfExpression831571

Note: C:\ptc\Windchill_10.2\Windchill\temp\WfExpression831571.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

1 error

Syntax check complete.

Translate
1-Visitor
Mar 4, 2015 12:44 PM UTC

Hi Zane,

Without seeing your full code I cannot comment too much on your error.

It seems though that you are trying to use a variable "IBAValue_VM_Name" which you have not declared anywhere in your code and this is the source of your error.

Regards,

Toby

Translate