Skip to main content
5-Regular Member
April 4, 2023
Solved

Create Document with WTDocument Subtype from Workflow Expression Robot

  • April 4, 2023
  • 1 reply
  • 2826 views

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);

 

 

 

 

 

 

 

 

 

 

 

 

 

Best answer by HelesicPetr

hi It does not work this way

 

you need to use different API

 

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

1 reply

HelesicPetr
22-Sapphire II
22-Sapphire II
April 4, 2023

hi It does not work this way

 

you need to use different API

 

document.setTypeDefinitionReference(TypedUtilityServiceHelper.service.getTypeDefinitionReference("wt.doc.WTDocument|com.myDocType"));
YannickM5-Regular MemberAuthor
5-Regular Member
April 4, 2023

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

YannickM5-Regular MemberAuthor
5-Regular Member
April 4, 2023

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.