Skip to main content
15-Moonstone
January 26, 2024
Solved

Can I create a document using the program from the object in the attachment table?

  • January 26, 2024
  • 1 reply
  • 2670 views

Can I create a document using the program from the object in the attachment table?

Best answer by HelesicPetr

Hi @avillanueva 
Iam sure that he is looking for a code to do so 😄

 

@smcvr Here is a code how to add/update primary content

CS237668 - How to update Primary Content

 

PS: fileStream can be any InputStream. So the "file" does not have to be on a disk but it can be just in memory. 

for example

I use a findContentStream to read a AppData 

 

 

InputStream is = ContentServerHelper.service.findContentStream(appData);

 

 

PetrH

1 reply

avillanueva
23-Emerald I
23-Emerald I
January 26, 2024

Need more info here? Are you talking about uploading code to attachments of a document and then having Windchill execute that? The security part of my brain is having a fit. Please elaborate.

smcvr15-MoonstoneAuthor
15-Moonstone
January 26, 2024

Hi @avillanueva,

No, I want to attach the document added by users in the Problem Report process to the Attachment table of another incoming document as Primary Content. For example, when a user initiates Problem Report number 1213, I create a general document before the task is assigned to the user. When the task is assigned to the user, they will upload the document to the attachment table under the problem report, and I want to add this document as Primary Content in the general document.

avillanueva
23-Emerald I
23-Emerald I
January 26, 2024

Yes, this can be done via a expression robot at the beginning of your Problem Report workflow. Recommend creating an external class with a static method that passes in the PBO, in this case the Problem Report. Assumption here is that the user uploads a file during the creation of a problem report that you want to take action on.

You'll need the following bit of code:

  • Grabbing attachments from change objects, specifically problem reports after you verify that a file exists.
  • Creating a WTDocument with all necessary fields and possibly IBAs
  • Copying that attachment to the primary content of the newly created document
  • Checking in the document. 
  • (Possible) - Associating to the Problem report? Not sure if that was part of your plan.

Recommend also that you keep track of results in case you want to pass those back to the workflow to make routing decisions in case of error or bad input.