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

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

SOLVED

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

ext is a custom class, however, we get booleans, strings, ints, longs from workflows with just java.

The code below can be tweaked to get different types from the workflows. We rolled these methods into a class in ext package as well.

Setting can also be done with a little more code as well. This code is not supported and in 10 there is a much more efficent way with code to get these variables from the workflow. Since you were asking for a sting I only included String but by chaning the casting around you should be able to get the rest of the types.

//Declares a attributeContainer of type DefaultAttributeContainer and gets the container with the function getAttributeContainer()
wt.iba.value.DefaultAttributeContainer attributeContainer=(wt.iba.value.DefaultAttributeContainer)ibaHolder.getAttributeContainer();

//Try Block used to catch a blank String
try
{
//Defines a attributeDefinition of type AttributeDefDefaultView that gets the variable in question (name in type/atribute manager.)
wt.iba.definition.litedefinition.AttributeDefDefaultView attributeDefinition=defService.getAttributeDefDefaultViewByPath("your var name here");
System.out.println("Size:"+attributeContainer.getAttributeValues(attributeDefinition).length);

//Declares attValue of type StringValueDefaultView (string, change for diff values) and sets it equal to the getAttributeValues function
wt.iba.value.litevalue.StringValueDefaultView attValue= (wt.iba.value.litevalue.StringValueDefaultView)attributeContainer.getAttributeValues(attributeDefinition)[0];

//Sets the StringVar = to previously defined attvalue.
StringVar=attValue.getValue();
System.out.println("StringVar");
}
catch (Exception e){System.out.println("Error getting attribute value,"+e.getMessage());}

This gets the value of a string named in the getAttributeDefDefaultViewByPath. This doesnt get multivalue strings, you will have to do more tweaking to get that a well but it is possiable.

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

You probably have to "refresh" your attribute container before calling these methods.

Docs/Parts/ChangeRequests/etc implement IBAHolder

WTDocument doc = findRandomDocument();

doc = (WTDocument)IBAValueHelper.service.refreshAttributeContainer(new IBAHolder[] { doc })[0];

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

Matt is right. I forgot the first 2 lines of the method. OPS!

//Declares a ibaHolder of type IBAHolder and sets it equal to IBAHolder of the PBO from the function refreshAttributeContainer
wt.iba.value.IBAHolder ibaHolder=wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer((wt.iba.value.IBAHolder)primaryBusinessObject, null, null, null);

//Declares a DefService of type StandardIBADefinitionService and sets it to StandardIBADefinitionService function
wt.iba.definition.service.StandardIBADefinitionService defService=new wt.iba.definition.service.StandardIBADefinitionService();

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

Well I tried the following (which is a combination of both of Matthew Hoover's posts):

//Declares a ibaHolder of type IBAHolder and sets it equal to IBAHolder of the PBO from the function refreshAttributeContainer

wt.iba.value.IBAHolder ibaHolder=wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainer((wt.iba.value.IBAHolder)primaryBusinessObject, null, null, null);

//Declares a DefService of type StandardIBADefinitionService and sets it to StandardIBADefinitionService function

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

//Declares a attributeContainer of type DefaultAttributeContainer and gets the container with the function getAttributeContainer()

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

//Try Block used to catch a blank String

try

{

//Defines a attributeDefinition of type AttributeDefDefaultView that gets the variable in question (name in type/atribute manager.)

wt.iba.definition.litedefinition.AttributeDefDefaultView attributeDefinition=defService.getAttributeDefDefaultViewByPath("UpdateJobs");

System.out.println("Size:"+attributeContainer.getAttributeValues(attributeDefinition).length);

//Declares attValue of type StringValueDefaultView (string, change for diff values) and sets it equal to the getAttributeValues function

wt.iba.value.litevalue.StringValueDefaultView attValue= (wt.iba.value.litevalue.StringValueDefaultView)attributeContainer.getAttributeValues(attributeDefinition)[0];

//Sets the StringVar = to previously defined attvalue.

String StringVar=attValue.getValue();

System.out.println("StringVar");

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

result = "SUCCESS";

} else {

result = "FAIL";

}

}

catch (Exception e){System.out.println("Error getting attribute value,"+e.getMessage());}

The parts in bold that I either added or changed or to suit my needs or because the syntax checker highlighted an error.

When I syntax check it, it says that there are no errors, however when it comes to runtime it falls over with a nullPointer exception?

The attribute I am currently trying to pull up is called "Update Jobs" (logical identifier "UpdateJobs") and it is on a change notice - I tried using both as the parameters in the getAttributeDefDefaultViewByPath() method.

Am I right in thinking this can go in a wf and does not need to be in a class?

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

The server logs are saying the following:

Fri 11/18/11 05:43:42: WfPropagationQueue.PollingThread: ECN name: Attribute Grabber 004

Fri 11/18/11 05:43:42: WfPropagationQueue.PollingThread: Size:0

Fri 11/18/11 05:43:42: WfPropagationQueue.PollingThread:Error getting attribute value,0

Fri 11/18/11 05:43:42: WfPropagationQueue.PollingThread: wt.util.WTException: wt.workflow.definer.InvalidEventException: null event

Fri 11/18/11 05:43:42: WfPropagationQueue.PollingThread: Nested exception is: wt.workflow.definer.InvalidEventException: null event

(I got an identical log entry for each of the attempts I made)

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

Put it in a main and see what it does. add e.printStackTrace() so you can see where it fails.

Change System.out.println("StringVar") to System.out.println("StringVar: " + StringVar); so you know what's in it. Can it be null? Account for that.

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

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();

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

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

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

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);

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

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