Skip to main content
Nov 30, 2016 6:37 PM UTC
Solved

Conditional routing based on Document attributes

Hello all,

I am trying to have a conditional routing in a workflow, based on a specific attribute of the routed document.

In the expression I use this:

//get the attributes of the document.
wt.iba.value.IBAHolder holder = wt.iba.value.service.IBAValueHelper.service.refreshAttributeContainerWithoutConstraints(doc);
wt.iba.value.DefaultAttributeContainer ac = (wt.iba.value.DefaultAttributeContainer) holder.getAttributeContainer();

if (ac != null) {
wt.iba.value.litevalue.AbstractValueView[] avalues = ac.getAttributeValues();

for (int i=0;i<avalues.length;i++) {
wt.iba.value.litevalue.AbstractValueView val = avalues[i];
if (val.getDefinition().getName().equals("contracttype")) IPselect= val.getLocalizedDisplayString();
break;
}
}
}catch(Exception e) { System.out.println("Caught Exception:" + e.toString()); }

Then in the OR I have put this:

result="IP_Yes";

if (IPselect.equalsIgnoreCase("Consulting")) result="IP_No";

if (IPselect.equalsIgnoreCase("Service Agreement")) result="IP_No";

The problem I have is that some times it gets the value from the document (thus "IPselect" has a value in the workflow) and some others not.

Any ideas?

Thank you in advance

John

Dec 1, 2016 7:45 AM UTC

It is solved. I found the error.

Originally I was telling to check this:

              

                if (val.getDefinition().getName().equals("contracttype")) IPselect= val.getLocalizedDisplayString();

                break;

So the if was break at the first attribute it was getting (any attribute). Obvisously it was not the one i wanted. So I have put the break inside like that:

                if (val.getDefinition().getName().equals("contracttype")) {

                IPselect= val.getLocalizedDisplayString();

                break;

                }

So now it will check all the attributes, and it will stop when it will get the "contracttype".

Regards

John

7 replies

Dec 1, 2016 6:52 AM UTC

Thank you for your comment.

The problem is that when the process run, sometimes I get the value of the attribute and sometimes not.

Regards

John

ipsomiadisAuthorAnswer
Dec 1, 2016 7:45 AM UTC

It is solved. I found the error.

Originally I was telling to check this:

              

                if (val.getDefinition().getName().equals("contracttype")) IPselect= val.getLocalizedDisplayString();

                break;

So the if was break at the first attribute it was getting (any attribute). Obvisously it was not the one i wanted. So I have put the break inside like that:

                if (val.getDefinition().getName().equals("contracttype")) {

                IPselect= val.getLocalizedDisplayString();

                break;

                }

So now it will check all the attributes, and it will stop when it will get the "contracttype".

Regards

John

Dec 1, 2016 3:50 PM UTC

Good for:

- keeping all brain cells really busy and working hard

- keeping us all humble

How good you feel when you find the problem seems to be in proportion to how hard it is to find the problem.

Dec 29, 2016 11:38 PM UTC

Ioannis Psomiadis‌,

You may want to consider switching over from wt.iba.value.IBAHolder to com.ptc.core.lwc.server.PersistableAdapter.  I think your code is being deprecated.  And the new code is fewer lines.  Check it out in the context of the other posting:  Re: PBO Attribute captured in a workflow‌

doc = (wt.doc.WTDocument)primaryBusinessObject;  // you can skip this - you already instantiated "doc"

com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(doc,null,null,null);

obj.load("contracttype");

IPselect = (String)obj.get("contracttype");

Jan 4, 2017 3:35 PM UTC

Happy New Year Ben,

Thank you for your tip. I will test it in our development environment and I will let you know.

Regards

John