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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

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

smcvr
14-Alexandrite

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

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

ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

9 REPLIES 9
avillanueva
22-Sapphire II
(To:smcvr)

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.

smcvr
14-Alexandrite
(To:avillanueva)

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
22-Sapphire II
(To:smcvr)

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.

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

smcvr
14-Alexandrite
(To:HelesicPetr)

Hi @HelesicPetr ,

Thank you for your response.
I started creating the code. I am trying to create a new document in the flow and load the document in the attachment table into that document. But there was an error in my code and I couldn't solve it.

 

CODE:

 DataFormatReference newdfr = getDataFormat(appData.getBusinessType());

 

ERROR:

WfExpression_2287132672.java:122: error: cannot find symbol
        wt.content.DataFormatReference newdfr = getDataFormat(appData.getBusinessType());
                                                ^
  symbol:   method getDataFormat(String)
  location: class WfExpression_2287132672
Note: WfExpression_2287132672.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: WfExpression_2287132672.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error

 

 

HelesicPetr
22-Sapphire I
(To:smcvr)

Hi

If you write a code directly in A worlflow
You have to use full class definition
wt.doc.WTDocument instead of WTDocument
This apply for all used classes in your case the dataformat reference
 
also you have to check if your windchill version contains that class
 
i recomand to use java ide to write code
i use InteliJIdea but eclips is ok

PS getDataFormat method misses class definition or instance
class.method()
instance.method()
 
PetrH

sent from iPhonu
avillanueva
22-Sapphire II
(To:HelesicPetr)

Also recommend that before deploying in production, you take that code and move it to an external class. This way if you have a bug or need to make changes, you can do that without destroying an executing workflow. If you have too much code in the workflow expression robot itself, any issues will force you to start the workflow process all over again.

Agree with @avillanueva 

If you use code to do something and you would change it, then the external code is easier to change and you do not involve the workflow.

If you need to change the code directly in the workflow, then you always need to start new workflow process and can not continue in already executed one.

PetrH

smcvr
14-Alexandrite
(To:HelesicPetr)

Hi @HelesicPetr  and @avillanueva ,

 

Thanks for your help 🙂

Announcements

Top Tags