Skip to main content
1-Visitor
November 16, 2016
Question

How to pass a datashapeName as parameter.

  • November 16, 2016
  • 3 replies
  • 3722 views

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.

3 replies

1-Visitor
November 16, 2016

A string using double quotes "YourDataShape" usually works

1-Visitor
November 16, 2016

I alreay tried  that but no success.

1-Visitor
November 16, 2016

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.

1-Visitor
November 17, 2016

At the run time i get this warning.

warn.png

1-Visitor
November 17, 2016

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.