Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
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);
Solved! Go to Solution.
hi It does not work this way
you need to use different API
document.setTypeDefinitionReference(TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.doc.WTDocument|com.myDocType"));
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
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.
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
plus subtype
Hope this can help.
PetrH
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
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