7 Replies Latest reply on May 18, 2017 12:20 PM by vr-2 RSS
    nbhagtani Explorer

    How to all names of properties of thing template?

    How i can get list of all properties defined in thing template?

    GetNamedProperties -> service takes json but i don't have any parameter just need all properties list.

      • Re: How to all names of properties of thing template?
        anna Communicator

        Dear Nisha,

        You could author it like this:

        Attached code here:

         

        var params = {
         category: undefined /* STRING */,
         type: undefined /* BASETYPENAME */,
         dataShape: undefined /* DATASHAPENAME */
        };
        // result: INFOTABLE dataShape: "PropertyDefinition"
        var propertys = me.GetPropertyDefinitions(params);
        var propertyList = new Array();
        var tableLength = propertys.rows.length;
        for (var x = 0; x < tableLength; x++) {
         var row = propertys.rows[x];
         //Your code here
            logger.error(row.name);
            propertyList.push(row.name);
        }
        
        
        

         

         

         

        Br,

        Anna

        • Re: How to all names of properties of thing template?
          vr-2 Explorer

          Hi,

           

          var params = {

            category: undefined /* STRING */,

            type: undefined /* BASETYPENAME */,

            dataShape: undefined /* DATASHAPENAME */

          };

           

           

          // result: INFOTABLE dataShape: PropertyDefinition

          var info1 = Things["YOURTHING"].GetPropertyDefinitions(params);

          var params = {

          infoTableName: undefined /* STRING */

          };

           

           

          // result: INFOTABLE

          var infotable = Resources["InfoTableFunctions"].CreateInfoTable(params);

           

           

          //Add a new field to the InfoTable:

          infotable.AddField({name: "PropertyName", baseType: "STRING"});

          infotable.AddField({name: "BaseType", baseType: "STRING"});

          var newEntry = new Object();

           

              for (var  i =0; i<info1.getRowCount(); i++)

              {

            newEntry.PropertyName = info1.rows[i].name;

            newEntry.BaseType = info1.rows[i].baseType;

            infotable.AddRow(newEntry);      

              }

           

          var result = infotable

           

           

          Hope this will work.

           

          Create Thing for your ThingTemplate and Replace "YOURTHING" with ThingName

           

          Set your service output as infotable.