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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

How to create subtype of WTDocument by API?

WhiteChen
8-Gravel

How to create subtype of WTDocument by API?

We can use API to create new WTDocument, but we have a subtype under WTDocument, how can I create a subtype by API? Who could help me? Thanks in advanced.

ACCEPTED SOLUTION

Accepted Solutions
RandyJones
20-Turquoise
(To:WhiteChen)


@WhiteChen wrote:

We can use API to create new WTDocument, but we have a subtype under WTDocument, how can I create a subtype by API? Who could help me? Thanks in advanced.


I know of 2 ways to do this. Method 1 where you find the TypeDefinitionReference and set the doc type and method 2 by using the PersistableAdapter.

 

Method 1:

//find the TypeIdentifier
TypeIdentifier myCustomType = TypeHelper.getTypeIdentifier("WCTYPE|wt.doc.WTDocument|com.mydomain.Document.myCustom");

//cast to WCTypeIdentifier
WCTypeIdentifier myCustomWCType = (WCTypeIdentifier) myCustomType;

//find the TypeDefinitionReference
TypeDefinitionReference myCustomTDR = TypedUtilityServiceHelper.service.getTypeDefinitionReference(myCustomWCType.getTypename());

//create doc
WTDocument doc = WTDocument.newWTDocument();

//set the doc TypeDefinitionReference
doc.setTypeDefinitionReference(myCustomTDR);

 

Method 2:

//Use the PersistableAdapter
PersistableAdapter obj = new PersistableAdapter("com.mydomain.Document.myCustom", locale, new CreateOperationIdentifier());

View solution in original post

3 REPLIES 3
RandyJones
20-Turquoise
(To:WhiteChen)


@WhiteChen wrote:

We can use API to create new WTDocument, but we have a subtype under WTDocument, how can I create a subtype by API? Who could help me? Thanks in advanced.


I know of 2 ways to do this. Method 1 where you find the TypeDefinitionReference and set the doc type and method 2 by using the PersistableAdapter.

 

Method 1:

//find the TypeIdentifier
TypeIdentifier myCustomType = TypeHelper.getTypeIdentifier("WCTYPE|wt.doc.WTDocument|com.mydomain.Document.myCustom");

//cast to WCTypeIdentifier
WCTypeIdentifier myCustomWCType = (WCTypeIdentifier) myCustomType;

//find the TypeDefinitionReference
TypeDefinitionReference myCustomTDR = TypedUtilityServiceHelper.service.getTypeDefinitionReference(myCustomWCType.getTypename());

//create doc
WTDocument doc = WTDocument.newWTDocument();

//set the doc TypeDefinitionReference
doc.setTypeDefinitionReference(myCustomTDR);

 

Method 2:

//Use the PersistableAdapter
PersistableAdapter obj = new PersistableAdapter("com.mydomain.Document.myCustom", locale, new CreateOperationIdentifier());

Hi Randy,

Appreciate your answer, your code is worked for me. One more question, how can I fill up the attributes when the document is created? The cutomized attributes as picture show.

Thanks.

RandyJones
20-Turquoise
(To:WhiteChen)


@WhiteChen wrote:

Hi Randy,

Appreciate your answer, your code is worked for me. One more question, how can I fill up the attributes when the document is created?


Check out this PTC article and keep in mind that LWCNormalizedObject has been replaced with PersistableAdapter

https://www.ptc.com/en/support/article?n=CS135663

Announcements

Top Tags