Skip to main content
1-Visitor
November 6, 2017
Question

Upload a file for a wt document from thingworx

  • November 6, 2017
  • 3 replies
  • 10240 views

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

3 replies

16-Pearl
November 20, 2017

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

1-Visitor
November 20, 2017

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.

12-Amethyst
November 24, 2017

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

1-Visitor
December 5, 2017

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

12-Amethyst
December 5, 2017

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

1-Visitor
December 7, 2017

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

12-Amethyst
December 7, 2017

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