5 Replies Latest reply on Nov 17, 2016 7:31 AM by amarthouna RSS
    egolindano Explorer

    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.

      • Re: How to pass a datashapeName as parameter.
        sdejager Explorer

        A string using double quotes "YourDataShape" usually works

          • Re: How to pass a datashapeName as parameter.
            egolindano Explorer

            I alreay tried  that but no success.

              • Re: How to pass a datashapeName as parameter.
                sdejager Explorer

                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.

            • Re: How to pass a datashapeName as parameter.
              egolindano Explorer

              At the run time i get this warning.

              warn.png

              • Re: How to pass a datashapeName as parameter.
                amarthouna Apprentice

                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.