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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Upload a file for a wt document from thingworx

SaranKarthick
16-Pearl

Upload a file for a wt document from thingworx

Hi,

I'm working on a POC where the customer want to create a Issue document in windchill. They also want to attach a file along with the document. I am able to create the document using the below given service.(The property values were hardcoded for test purposes. But i intend to get it from the user)

var params = {

    infoTableName : "InfoTable",

    dataShapeName : "demo.wt.doc.WTDocument"

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(ptc-demoProblemReportShape)

var newDocument = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

newDocument.AddRow({

    name: "TestDocument1",

    number: "000001",

//    'state--state': "Released",

//    'versionInfo--identifier--versionId': "A",

    type: "wt.doc.WTDocument",

    containerReference: "OR:wt.inf.container.ExchangeContainer:5:219321006-1506495753013-268599241-1-56-168-192@blrmaigwd27067.itcinfotech.com",

    'folderingInfo--cabinet': "OR:wt.folder.Cabinet:280:219321006-1506495753013-268599241-1-56-168-192@blrmaigwd27067.itcinfotech.com"

});

var params = {

    dataShape: 'demo.wt.doc.WTDocument' /* DATASHAPENAME */,

    objects: newDocument /* INFOTABLE */

};

// result: INFOTABLE dataShape: "undefined"

var createdDocument = me.Create(params);

var result = createdDocu

With this service i'm able to create the WT Document in windchill. But i can't succeed in attaching a file to this document. Should i add the file as one of the properties of the document?

Please provide a methodology for my requirement.

Thanks and Regards
SaranKarthick

11 REPLIES 11

Hi Saran,

I did not test in a recent release of Navigate (probably 1.1) and maybe a specialized Windchill REST API has been introduced since then ...

However if you want to pursue with I*E based Windchill Connector Services, Content Holder creation is generally a 3 stages process :

1. Obtain the upload link for the file to upload :

     <Windchill connector>::GetUploadHandles(...)

2. Upload the content into the WNC staging area using a generic POST and the URL link obtained from GetUploadHandles :

     Resources["ContentLoaderFunctions"].PostText(...)

3. Create the Content holder using the info obtained from GetUploadHandles :

     <Windchill connector>::CreateContentHolder(...)

I don't have a working example handy, but if I remember, it was important to use the following headers at steps 2 (PostText).

     Content-Disposition: attachment; filename=<filename>

     Content-Type: application/octet-stream

Hi Stephane,

Thanks for your reply. I am successful in creating a document and uploading a file to it. I had used 'Create','Add Content','Get Upload Handles' of the 'ptc-windchill-demo-thing' to do the respective actions. But the issues I'm facing are:

  • Since I create the doc first and then attach a file to it in a single service, the created doc takes 'A.2' version during its first creation itself.
  • Windchill and the Thingworx must be available on the same system itself.

So I'm curious to use the 'Create Content Holder' service which I think will solve my version issue. Please provide guidance.

Hi Saran,

I'm also trying to do the file upload for a customer project. Could you explain me how you have used the Upload Handles service? How does the input has to look like? I already tried to use an hyperlink to the file I want to upload as well as an directory path to the file.

Regards,

Niklas

Hi Niklas Eisenhuth,

Sorry I couldn't reply early. For the service 'GetUploadHandles' the input is just the file name eg.: Test.txt,...  Once give it will provide you with the method and URL which is the input for the 'AddContent' service. Hope this helps.

Thanks and Regards,

Saran

Hi Saran,

The 'Create Content Holder' is a service which combines the functionality of 'Create' and 'Add Content'. S simply provide the infotable and dataShape and upload handles which you used for the 'Create' and 'Add Content' service. This worked for me when I create a single object in Windchill with attachments.

Hope this helps,

Niklas

Hi Stephane,

I have provided Filename as an input parameter to the GetUploadHandel service where i got URL with file name append to it. but i am not able to figure out how to use those URL to upload file to the WNC staging area from Thingworx .

I have also tried Saran Karthick K R​ as you mentioned to use Resources["ContentLoaderFunctions"].PostBinary() to upload file still it's not working.

So i am not able use AddContent service to attach file to the WTDocument.

Please help me. Saran Karthick K RNiklas Eisenhuth​ @ whoever worked on that.

Hi Michael Neumann,

I used Create service to create a wtdocument and then with 'GetUploadHandles' i got the URL and the method which will be used along with the created documents ufid in the 'AddContent' service. Hope this service flow makes sense.


Thanks and Regards

Saran

Hello all,

since there are a lot of people who had the same problem, I have attached 2 example entities which demonstrate the creation of an WT Document in Windchill via ThingWorx while you can directly provide a file which shall be attached to that WT Document. To make this work you will need of course the Windchill Extension (I have used version 1.7)

I hope this will help to understand how to use the services.

Regards,

Niklas

Hello Niklas,

I am trying to do the same thing but for 'Quality Record' instead of documents.

Could you please help me with datashape i have to provide in CreateContentHolder for this?

And also in datashape what will be the type?

Thanks and Regards,

Prasoon Kumar

Hello Prasoon,

I could not find the Type 'Quality Record' on my default Windchill System. Is this maybe a sub type of another type?

To create a Data Shape for that type you will need the internal name of it. If you have that, you can simply execute the service CreateDataShapes ​on your Windchill Connector Thing. You will need to provide your internal type name and a Prefix for the DataShape Name and it will generate you a Data Shape for your specified type.

Regards,

Niklas

Thank you Niklas. It worked.

I want to ask you one more question.

The above service you shared,it adds the file into primary(initial content) attachment of Document.

What if i want to add the file in secondary attachment?

Thanks and Regards,

Prasoon Kumar

Top Tags