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
Hi Guys,
I am completely new at customization and inquisitive for knowledge Thank you for your help in Advance !
i wanted to send the number/name of the Part in the Header of the Review PR Task Mail during the Promotion Notice (Workflow).
For that i created the Variables PR_Description, Part_Number, Part_Name in the Workflow Properties/Variables and added the following code to the first conditional.
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;
wt.part.WTPart prt = (wt.part.WTPart)primaryBusinessObject;
PR_Description = ext.testpackage.Promotionhelper.get_pn_desc(pn);
Part_Number = ext.testpackage.Promotionhelper.get_part_number(prt);
Part_Name = ext.testpackage.Promotionhelper.get_part_name(prt);
The created class includes the following:
package ext.testpackage;
import wt.maturity.PromotionNotice;
import wt.part.WTPart;
public class Promotionhelper {
public static void main(String args[]) {
System.out.println("test");
}
public static String get_pn_desc (PromotionNotice pn) {
return pn.getDescription();
}
public static String get_part_number (WTPart prt) {
return prt.getNumber();
}
public static String get_part_name (WTPart prt) {
return prt.getName();
}
The PR_Description works perfectly. It got the mail with the Description, but for PartName and PartNumber i got the following:
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: Caused by: java.lang.ClassCastException: wt.maturity.PromotionNotice cannot be cast to wt.part.WTPart
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: at wt.workflow.expr.WfExpression39493.execute_ROUTER_EXPRESSION_(WfExpression39493.java:40)
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: at java.lang.reflect.Method.invoke(Method.java:597)
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: at wt.workflow.definer.WfExpression.executeRouter(WfExpression.java:2715)
Mo 6/3/13 14:02:05: WfPropagationQueue.PollingThread: ... 15 more
Do you have any clue how i can get the PartName and PartNumber for the Object in Promotion Notice?
Solved! Go to Solution.
Daniel,
The clue to what's wrong is actually in the error thrown: "java.lang.ClassCastException: wt.maturity.PromotionNotice cannot be cast to wt.part.WTPart" which is due to wt.part.WTPart prt = (wt.part.WTPart)primaryBusinessObject;. In a Promotion Notice workflow the primaryBusinessObject is a PromotionNotice object. You can not just cast that to a WTPart. Luckily there is a helper method which given your pn object can query for the object(s) the user wants to promote. So replace the broken line with something like this:
wt.fc.WTObject obj;
wt.fc.QueryResult queryresult = wt.maturity.MaturityHelper.service.getPromotionTargets(pn);
while (queryresult.hasMoreElements()) {
obj = (wt.fc.WTObject) queryresult.nextElement();
if (obj instanceof wt.part.WTPart) {
// ... cast to WTPart and query for name/number here ...
}
}
Depending on your use case you probably want to add some extra handling there to account for other types of objects that your users can (try to) promote whith proper error handling etc.
In general regarding the Windchill API look for wt.<sometype>.XxxHelper.service.someMethod() if you have a wt.<somepackage>.SomeClass which does not give you the methods you need. Also read up on wt.fc.QueryResult and friends it's useful all over the place as a common Windchill pattern.
Cheers,
Jorn
Daniel,
The clue to what's wrong is actually in the error thrown: "java.lang.ClassCastException: wt.maturity.PromotionNotice cannot be cast to wt.part.WTPart" which is due to wt.part.WTPart prt = (wt.part.WTPart)primaryBusinessObject;. In a Promotion Notice workflow the primaryBusinessObject is a PromotionNotice object. You can not just cast that to a WTPart. Luckily there is a helper method which given your pn object can query for the object(s) the user wants to promote. So replace the broken line with something like this:
wt.fc.WTObject obj;
wt.fc.QueryResult queryresult = wt.maturity.MaturityHelper.service.getPromotionTargets(pn);
while (queryresult.hasMoreElements()) {
obj = (wt.fc.WTObject) queryresult.nextElement();
if (obj instanceof wt.part.WTPart) {
// ... cast to WTPart and query for name/number here ...
}
}
Depending on your use case you probably want to add some extra handling there to account for other types of objects that your users can (try to) promote whith proper error handling etc.
In general regarding the Windchill API look for wt.<sometype>.XxxHelper.service.someMethod() if you have a wt.<somepackage>.SomeClass which does not give you the methods you need. Also read up on wt.fc.QueryResult and friends it's useful all over the place as a common Windchill pattern.
Cheers,
Jorn
Thank you for the Answer 🙂