Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X
For Scenario 1A:
package ext.mytest;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: </p>
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
import wt.rule.algorithm.RuleAlgorithm;
import wt.enterprise.EnterpriseHelper;
import wt.util.WTException;
import wt.inf.container.WTContainerRef;
import java.util.TimeZone;
import java.text.*;
import java.util.*;
public class customNumberRule implements RuleAlgorithm {
public Object calculate(Object args[], WTContainerRef container) throws //
WTException {
// Add current date to the end of the generated number
String num = EnterpriseHelper.getNumber(args); //This is OOTB
Calendar gmtlocal = new GregorianCalendar(TimeZone.getTimeZone("GMT+8"));
SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
sf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
num = sf.format(gmtlocal.getTime())+"-" + num;
return num;
}
}
For Scenario 1B:
public class customNumberRule implements RuleAlgorithm {
public Object calculate(Object args[], WTContainerRef container) throws WTException {
String num= "";
if (args!=null && args.length>0) {
for (int i=0; i<args.length; i++) {
if (args[i] instanceof java.sql.Timestamp) {
Date date = new Date(((java.sql.Timestamp)args[i]).getTime());
num += wt.util.WTStandardDateFormat.format(date, "yyyyMMdd");
}
else
num += args[i].toString();
}
}
return num;
}
package ext;
import wt.enterprise.EnterpriseHelper;
import wt.inf.container.WTContainerRef;
import wt.rule.algorithm.RuleAlgorithm;
import wt.util.WTException;
import wt.util.WTProperties;
public class VariableCNNumberPrefix implements RuleAlgorithm {
public Object calculate(Object args[], WTContainerRef container) throws WTException {
// Determine the server hostname
String serverHostName = "";
try {
serverHostName = WTProperties.getLocalProperties().getProperty("wt.rmi.server.hostname");
} catch (Throwable t) {
}
// OOTB code to get the next number in the sequence
String num = EnterpriseHelper.getNumber(args);
// Set the default prefix, and change it if we're on a different server
String prefix = "ECN";
if (serverHostName.equals("<enter_test_server_name_here>")) {
prefix = "TST";
}
// Concantentate the prefix with the number from the ECO number.
num = prefix + num;
return num;
}
}
<AttrValue id="number" algorithm="com.ptc.windchill.enterprise.revisionControlled.server.impl.NumberGenerator">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
</AttrValue>
To (scenario 1A):
<AttrValue id="number" algorithm="ext.mytest.customNumberRule">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
</AttrValue>
OR (scenario 1B):
<AttrValue id="number" algorithm="ext.mytest.customNumberRule">
<Arg>{GEN:wt.enterprise.SequenceGenerator:WTPARTID_seq:10:0}</Arg>
<Attr id="<dateTypeAttribute>"/>
</AttrValue>