Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Following on from http://communities.ptc.com/message/190893#190893, we have been able to get the "containerName" attribute value set as a prefix for the autogenerated numbers for WTParts, by adding these lines to the OOTB OIR :
<!-- add OUR PREFIX for the Part No -->
<Value algorithm="wt.rule.algorithm.StringConstant"><Attr id="containerName"/>
</Value>
<Arg>-</Arg>
<!-- the sequence -->
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:6:0}</Arg>
The extra Arg line shown above simply puts the "-" character in-between the string and the number (and we have tested that this works).
But now we need to trim the text string returned by StringConstant to only use the first 5 characters of that string, so we have tried combining it in several different ways with a SubString algorithm for example using a VarDef & VarRef pair, or more directly by wrapping the 3 lines shown above in green with the following additional lines :
<Value algorithm="wt.rule.algorithm.SubString">
<Value algorithm="wt.rule.algorithm.StringConstant">
<Attr id="containerName"/>
</Value>
<Arg>0</Arg>
<Arg>5</Arg>
</Value>
But whichever way we do it gives errors. Hence we have a few questions :
1. Is there a way to use the value of the "containerName" attribute as the first argument of the SubString algorithm ? If so how ?
2. If instead we add a Global Attribute (text string) to the Product container type definition in Type & Attribute Manager, we can set this to be the 5-character prefix that we need simply by setting the correct attribute value on the Product details page. We have tried this but got stuck again as the OIR cannot find or use the new attribute. So what is the correct format to use to specify our custom attribute in the OIR instead of Attr id="containerName" ?
3. We have tried using the Logical Identifier and the Display Name (which matches the Internal Name shown on Product-Attributes page) for the new attribute in the OIR instead of containerName, but these all gives a NullPointerException or other similar error. Should we be using some sort of 'full path name' based on wt.pdmlink.PDMLinkProduct ?
4. Are there some unwritten rules about how to name Global Attributes, add them to a container type and then use them in Doc or WTPart OIRs ?
Have you tried leaving off the StringConstant lines and just use the containerName attribute? Like this:
<Value algorithm="wt.rule.algorithm.SubString">
<Attr id="containerName"/>
<Arg>0</Arg>
<Arg>5</Arg>
</Value>
It works this way with the number field of the part (when not autogenerated).
Thanks for the suggestion, which I have just tried. The editied OIR loads OK, but when I make a new WTPart if gives this error :
In the Method Server log, there are many lines with similar error messages about NoClassDefFoundError and wrong name: wt/rule/algorithm/SubString.
...and after reading that message carefully again, it does tell us the answer - we should not be using a capital S in the middle of the name Substring !!
In the Windchill Help Centre, on the page about Default Value Algorithms, there are 15 listed and this is the only one that is not set in "CamelCase" !
So just to explain what we have done is to edit a copy of the OOTB Site level OIR for WTParts as shown below. We are testing it in a Product based on the General Product template (not the OOTB Product Design template, which has additional rules), and we loaded the new OIR at the Org level so that it applies to all Products under the Org domain. All of the changes we made are coloured green below... and this now works :
<!-- set the number to a generated number WITH OUR PREFIX -->
<AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<!-- add a V prefix for variant parts -->
<Value algorithm="wt.rule.algorithm.BooleanBranch">
<Value algorithm="wt.rule.algorithm.EqualsTest">
<Attr id="genericType"/>
<Arg>variant</Arg>
</Value>
<Arg>V</Arg>
<Arg></Arg>
</Value>
<!-- now add OUR PREFIX followed by a DASH -->
<Value algorithm="wt.rule.algorithm.Substring">
<Attr id="containerName"/>
<Arg>0</Arg>
<Arg>5</Arg>
</Value>
<Arg>-</Arg>
<!-- the sequence WITH REDUCED NUMBER OF DIGITS TO 6 -->
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:6:0}</Arg>
</AttrValue>
Hopefully others will find this useful too.