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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to pass a datashapeName as parameter.

egolindano
7-Bedrock

How to pass a datashapeName as parameter.

Hello everyone, is there anyway to correctly pass a datashapeName as a parameter to a thingworx service? i've try to send a string, but after i execute the services it throws me an error about the dataShape being null.

Thank You for your time.

5 REPLIES 5

A string using double quotes "YourDataShape" usually works

I alreay tried  that but no success.

I have tried this basic setup and it works for me:
A test service which creates a infotable from a datashape and has a string input test:

var params = {

  infoTableName : "InfoTable",

  dataShapeName : test

};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(testDS)

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

A test2 service which calls the test service:

var params = {

  test: "testDS" /* STRING */

};

// result: INFOTABLE dataShape: "testDS"

var result = me.test(params);

And a datashape testDS with a few fields.
I get no issues with either of the services.

I hope this information helps you.

At the run time i get this warning.

warn.png

There is a already a data type in ThingWorx called DATASHAPENAME. you can use this or simply use a string also; both has the same result except if you use DATASHAPENAME, you can search existing DataShapes from a dropdown when you run/ test the script.

Here is the steps:

1. Create a Service with a input. Called the Input Parameter Name as say "myDSName". (It can be either String or DATASHAPENAME). And set the service output as STRING.

2. Put the following snippet in the script window.

var result = DataShapes[myDSName].GetDescription();

3. When you run the script and pass an existing Data Shape Name (Description of the Data Shape name should not be empty) you will get the description of the Data Shape Name that you pass.

Note: Here you are running

GetDescription()

service to get the description. Similarly you can other script, create Data Table from the Data Shape etc.

Top Tags