cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Creating a Soft Type in a Java Expression

Toby.Pettit
1-Newbie

Creating a Soft Type in a Java Expression

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

ACCEPTED SOLUTION

Accepted Solutions

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;

}

}

View solution in original post

4 REPLIES 4

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.

Announcements

Top Tags