Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi All,
Does anyone know how you can create a soft type using a Java expression (to be used in a workflow).
For example to create a Change Notice:
wt.change2.WTChangeOrder2 co = wt.change2.WTChangeOrder2.newWTChangeOrder2();
But how about if I wanted to create a soft type of the Change Notice object called "HT Change Notice"?
Thanks in advance,
Toby
Solved! Go to Solution.
If you'd rather start with the WTTypeDefinition, something like this may work:
public static void main(String[] args) {
try {
String logicalID = "wt.doc.WTDocument";
TypeDefinition typeDefinition = getTypeDefinition(logicalID);
TypeDefinitionReference tdr = getTypeDefinitionReference(typeDefinition);
} catch (Exception e) {
e.printStackTrace();
}
}
private static TypeDefinitionReference getTypeDefinitionReference(TypeDefinition td) throws WTException, WTPropertyVetoException {
TypeDefinitionReference tdr = TypeDefinitionReference.newTypeDefinitionReference();
TypeDefinitionForeignKey key = TypeDefinitionForeignKey.newTypeDefinitionForeignKey();
key.setBranchId(td.getBranchIdentifier());
key.setId(PersistenceHelper.getObjectIdentifier(td).getId());
tdr.setKey(key);
return tdr;
}
private static TypeDefinition getTypeDefinition(String logicalID) {
try {
QuerySpec qs = new QuerySpec(WTTypeDefinition.class);
qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LOGICAL_IDENTIFIER,SearchCondition.EQUAL,logicalID),new int[]{0});
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LATEST_ITERATION,SearchCondition.IS_TRUE),new int[]{0});
return (TypeDefinition)PersistenceHelper.manager.find((StatementSpec)qs).nextElement();
} catch (Exception e) {
return null;
}
}
You need to get a TypeDefintionReference. There are several ways you can do that.
Let's assume you have the type String type = "wt.doc.WTDocument|com.CustomDocument"
Generally, it's something like this
TypeDefinitionReference tdr = wt.type.TypedUtility.getTypeDefinitionReference(type);
WTDocument doc = WTDocument.newWTDocument();
doc.setName(....)
doc.setNumber(...)
doc.setContainer(...)
doc.set.................
doc.setTypeDefinitionReference(tdr);
doc = (WTDocument)PersistenceHelper.manager.save(doc)
If you'd rather start with the WTTypeDefinition, something like this may work:
public static void main(String[] args) {
try {
String logicalID = "wt.doc.WTDocument";
TypeDefinition typeDefinition = getTypeDefinition(logicalID);
TypeDefinitionReference tdr = getTypeDefinitionReference(typeDefinition);
} catch (Exception e) {
e.printStackTrace();
}
}
private static TypeDefinitionReference getTypeDefinitionReference(TypeDefinition td) throws WTException, WTPropertyVetoException {
TypeDefinitionReference tdr = TypeDefinitionReference.newTypeDefinitionReference();
TypeDefinitionForeignKey key = TypeDefinitionForeignKey.newTypeDefinitionForeignKey();
key.setBranchId(td.getBranchIdentifier());
key.setId(PersistenceHelper.getObjectIdentifier(td).getId());
tdr.setKey(key);
return tdr;
}
private static TypeDefinition getTypeDefinition(String logicalID) {
try {
QuerySpec qs = new QuerySpec(WTTypeDefinition.class);
qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LOGICAL_IDENTIFIER,SearchCondition.EQUAL,logicalID),new int[]{0});
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTTypeDefinition.class,WTTypeDefinition.LATEST_ITERATION,SearchCondition.IS_TRUE),new int[]{0});
return (TypeDefinition)PersistenceHelper.manager.find((StatementSpec)qs).nextElement();
} catch (Exception e) {
return null;
}
}
Can the latter be used in a workflow expression? I have not tried the first post yet, but it is very similar to the expression that I have used to create a Change Notice in a workflow before so I shall try that one first.
Just about any compilable java can be used in a workflow expression (the WfExpression bodies are compiled into java classes). You must use full package names for anything outside of java.lang.