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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Create Document with WTDocument Subtype from Workflow Expression Robot

YannickM
4-Participant

Create Document with WTDocument Subtype from Workflow Expression Robot

Hello everybody,

 

I have a problem with setting the document Type of a new created Document from a expression Robot Workflow. I managed to create a WTDocument but cant set the subtype type.

 

I found this article, but could not get it to work: https://community.ptc.com/t5/Windchill/How-to-create-subtype-of-WTDocument-by-API/td-p/482345

 

Thank you for your help.

 

 

String name = "Test1234566788"; // Name
String number = "12343455677"; // Number
String lifeCycleName = "LC_TEST"; // Lifecycle name
String container_path = "/wt.inf.container.OrgContainer=Test/wt.inf.library.WTLibrary=Test"; // The container where the document will be created/located
String folder_path = "/Default"; // Folder path

wt.doc.WTDocument doc = wt.doc.WTDocument.newWTDocument();
doc.setName(name);
doc.setNumber(number);

/// ----------- TESTAREA -------------------------------
doc.setDocType(wt.doc.DocumentType.toDocumentType("WCTYPE|wt.doc.WTDocument|de.test.TESTDocument"));
/// ----------- TESTAREA -------------------------------

wt.inf.container.WTContainerRef containerRef = wt.inf.container.WTContainerHelper.service.getByPath(container_path);
doc.setContainerReference(containerRef);

wt.folder.Folder folder = wt.folder.FolderHelper.service.getFolder(folder_path,containerRef);
wt.folder.FolderHelper.assignLocation(doc, folder);

wt.lifecycle.LifeCycleTemplate lct = wt.lifecycle.LifeCycleHelper.service.getLifeCycleTemplate(lifeCycleName , doc.getContainerReference());
doc = (wt.doc.WTDocument) wt.lifecycle.LifeCycleHelper.setLifeCycle(doc, lct);

doc = (wt.doc.WTDocument) wt.fc.PersistenceHelper.manager.store(doc);

 

 

 

 

 

 

 

 

 

 

 

 

 

ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
22-Sapphire I
(To:YannickM)

hi It does not work this way

 

you need to use different API

 

document.setTypeDefinitionReference(TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.doc.WTDocument|com.myDocType"));

View solution in original post

7 REPLIES 7
HelesicPetr
22-Sapphire I
(To:YannickM)

hi It does not work this way

 

you need to use different API

 

document.setTypeDefinitionReference(TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.doc.WTDocument|com.myDocType"));
YannickM
4-Participant
(To:HelesicPetr)

Thank you for your fast reply. I'm getting the following error:

 

WfExpression_10773332627.java:45: error: package TypedUtilityServiceHelper does not exist

 

Windchill Version is 11.1 M020 CPS17

YannickM
4-Participant
(To:YannickM)

I have to add wt.type. before TypedUtilityServiceHelper Class

 

document.setTypeDefinitionReference(wt.type.TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.doc.WTDocument|com.myDocType"));

 

But now I get the following Exception:

 

wt.workflow.engine.FailedExpressionException: wt.util.WTException: The value of "Type Definition Reference" cannot be set to null, since it is a "required" attribute.

HelesicPetr
22-Sapphire I
(To:YannickM)

Hi @YannickM 

The string "wt.doc.WTDocument|com.myDocType" is full definition of Subtype WTDocument object so the subtype has to exist in type and attribute management.

.

go there and check what string definition is yours WTDocument subtype and use it. 

 

The string has to contains full definition same as my example. The separator is |

 

Main type

HelesicPetr_1-1680674297918.png

 

plus subtype

HelesicPetr_0-1680674236357.png

Hope this can help.

 

PetrH

YannickM
4-Participant
(To:HelesicPetr)

Thank yóu very much. I found my mistake. I had a sub-subtype of Document. So in your example a subtype of "My Doc Type". I only included the internal Name of the "Document" and my Subtype. So now I tried it with including the whole path and it works:

 wt.doc.WTDocument|com.myDocType|com.myDocType.mySubDocType

HelesicPetr
22-Sapphire I
(To:YannickM)

Hi @YannickM 

That's right if you use more levels you need to specify full path to subtype.

I'm glad that it works.
PetrH

HelesicPetr
22-Sapphire I
(To:YannickM)

String com.myDoctype is your subtype than has to exists in type and attribute management

Change it to your type


Odesláno z iPhonu
Announcements

Top Tags