Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hello all. Please help. I have an attribute indicating level of required approval rigour on documents and would like to route based on the value of the attribute. I'm not a java guru but, I have used an expression robot with the code below. I seem to be falling foul of the variable 'attrValues' and cannot understand why.
What I want to do is check the value of the IBA 'DocumentLevel' for all documents (there could be more than one) in the promotion notice and pass each individual value to a variable DocLevel. After that, a conditional task queries DocLevel to route accordingly based on the highest level.
Thanks in advance
Expression Code below: :-
+++++++++++++++++++++++++++++++++++++
//Use promotion request as basis.
wt.maturity.PromotionNotice promotionNotice = (wt.maturity.PromotionNotice) primaryBusinessObject;
System.out.println("promotionNotice: " + promotionNotice);
//Get all objects on the promotion request.
wt.fc.WTObject obj;
wt.fc.QueryResult queryResult = wt.maturity.MaturityHelper.service.getPromotionTargets(promotionNotice);
while (queryResult.hasMoreElements()) {
obj = (wt.fc.WTObject) queryResult.nextElement();
//MUltiple subtypes of wt.doc.WTDocument in use. so I'm using it as a catch-all of all doc types
if (obj instanceof wt.doc.WTDocument) {
//Get attribute values on the documents.
wt.doc.WTDocument doc = (wt.doc.WTDocument)obj;
com.ptc.core.lwc.server.PersistableAdapter attr = new com.ptc.core.lwc.server.PersistableAdapter(doc,null,null,null);
attr.load("DocumentLevel"); //internal name of the IBA
String attrValues = null;
DocLevel = (String)attr.get("DocumentLevel");
System.out.println("attrValues: " + attrValues);
//Check if workflow variable contains attribute vaules already and append if it doesn't.
if (DocLevel.isEmpty()) {
DocLevel = attrValues;
} else {
if (!DocLevel.contains(attrValues)) {
DocLevel += "," + attrValues;
}
}
}
}
System.out.println("DocLevel: " + DocLevel);
You are setting attrValues to null and not actually setting it to anything else anywhere in the posted code.
Your reply is much appreciated Randy. In my simple mind, initially setting it to null was to clear it before retrieved values are stored in it. I find that even if I comment out the line making it initially null, it still fails. Any other pointers?
Thanks
@csebilo wrote:
Your reply is much appreciated Randy. In my simple mind, initially setting it to null was to clear it before retrieved values are stored in it.
We that *is* your problem. You are NOT ever storing any values in that variable. Take a look at your posted code and you can see you do not have any
attrValues = <something>
You have to first put something in attrValues to actually have something in it.