12 Replies Latest reply on Apr 26, 2017 2:41 AM by nquirindongo RSS
    nquirindongo Newbie

    Get tags from Kepware -> add them to a thing in Thingworx

    Hi all,

     

    I just started using thinkworx and I'm trying to pull all the tags from Kepware to a thing in Thingworx (add it to a thing's properties). How I can do it using Javascript? I'm still learning what are the capabilities of the Thingworx Composer and its API. BTW I have the RemoteKEPServerEXThing installed.

      • Re: Get tags from Kepware -> add them to a thing in Thingworx
        anna Creator

        Dear Nelson,

        I believe the thing You've created RemoteKEPServerEXThing is based on Thing Template IndustrialGateway correct?

        If everything are configured properly according to our Help Center guide on How to Connect Kepware to ThingWorx, then you could create a new service on the thing you created:

         

        var params = {
          
                        filter: undefined /* STRING */,
          
                        path: "Simulation Examples.Functions" /* STRING */
          
        };
          
        
          
        // result: INFOTABLE dataShape: "IndustrialItems"
          
        var items = me.BrowseItems(params);
          
        logger.warn(items.length);
          
        var tableLength = items.rows.length;
          
        for (var x = 0; x < tableLength; x++) {
          
                        var row = items.rows[x];
          
                        logger.warn(row.Name);
          
            logger.warn(row.BaseType);
          
            
          
        var params = {
          
                        defaultValue: undefined /* STRING */,
          
                        description: undefined /* STRING */,
          
                        readOnly: undefined /* BOOLEAN */,
          
                        type: row.BaseType /* BASETYPENAME */,
          
                        remote: undefined /* BOOLEAN */,
          
                        remotePropertyName: row.Name /* STRING */,
          
                        timeout: undefined /* INTEGER */,
          
                        pushType: undefined /* STRING */,
          
                        dataChangeThreshold: undefined /* NUMBER */,
          
                        logged: undefined /* BOOLEAN */,
          
                        name: row.Name /* STRING */,
          
                        pushThreshold: undefined /* NUMBER */,
          
                        dataChangeType: undefined /* STRING */,
          
                        category: undefined /* STRING */,
          
                        persistent: undefined /* BOOLEAN */,
          
                        dataShape: undefined /* DATASHAPENAME */
          
        };
        me.AddPropertyDefinition(params);
        }
        

         

        And here you could pass a parameter to the path: "Simulation Examples.Functions" instead using a static one in my example.

        Btw, I keep other setting as undefined so you could give it definite value if you have special requirement for these settings.

        please let me know if it works for you.

         

        Thanks,

         

        Br,

        Anna

        • Re: Get tags from Kepware -> add them to a thing in Thingworx
          anna Creator

          Hi Nelson,

          Is your issue resolved? Please mark correct answer or Helpful for the answer if that helps you.

          Thanks,

           

          Br,

          Anna

            • Re: Get tags from Kepware -> add them to a thing in Thingworx
              nquirindongo Newbie

              Anna,

               

              Sorry for my delayed response and thanks for replying to my question.

               

              Your response was my first approach but running a "for loop" was not ideal. So, while I was learning how to use the tool I was able to write a service to browse groups from Kepware, get the items I want based on a filter expression and add them as properties.

               

              3 inputs: add (boolean), path (string), filter (string)

              1 output: result (infotable)

               

              // code start here

              var add = add;

               

              var inPathWithFilter = {
                  filter: filter /* STRING */,
                  path: path /* STRING */,
              };

               

              var result = me.BrowseGroups(inPathWithFilter);

               

              if(result.getRowCount() < 1) {  // function isEmpty() is not working for me
                  result = me.BrowseItems(inPathWithFilter);
              }

               

              if(add == true) {
                  //add additional fields to match the addItems infotable
                  var LoggedField= new Object();
                  LoggedField.name = "Logged";
                  LoggedField.baseType = 'BOOLEAN';
                  result.AddField(LoggedField);

               

                  var ScanRateMSField = new Object();
                  ScanRateMSField.name = "ScanRateMS";
                  ScanRateMSField.baseType = 'NUMBER';
                  result.AddField(ScanRateMSField);

               

                  var PersistentField= new Object();
                  PersistentField.name = "Persistent";
                  PersistentField.baseType = 'BOOLEAN';
                  result.AddField(PersistentField);

               

                  var whichTags = {
                      items: result /* INFOTABLE */
                  };
                 
                  result = me.AddItems(whichTags);
              }

                • Re: Get tags from Kepware -> add them to a thing in Thingworx
                  nquirindongo Newbie

                  I would like to do the same using data tables. How I can store the end results in a data table instead of an infotable.

                   

                  BTW... Do you know what are the main difference between a datatable and infotable?

                    • Re: Get tags from Kepware -> add them to a thing in Thingworx
                      anna Creator

                      Hi nquirindongo,

                      There is an article on our support website to introduce the difference between InfoTable and DataTable:

                      https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS224499&lang=en_US

                      I pasted it here in case you have no access to the support webside:

                       

                      • A DataTable persists its data by performing direct database writes to the Persistance Provider that ThingWorx is using
                      • An InfoTable persists its data in the form of a JSON object in the Persistance Provider that ThingWorx is using as well
                        • If the InfoTable Property has 400 rows, as an example, then a single JSON object would be created to represent that entire structure
                      • By using a DataTable to store incoming data there are direct service calls that can be made, such as AddDataTableEntry, to explicitly write a row to the DataTable entity
                        • This eliminates having to worry about managing custom services that could potentially overwrite or corrupt the entire DataTable
                      • When using an InfoTable property there is the possibility that somewhere in the custom services that the user has written that the property is being overwritten entirely or portions of it are
                        • This can lead to losing data where there is no way to retrieve what was lost upon the service completing
                        • This can also lead to some confusion on whether or not best practice is being followed to add rows to an existing InfoTable property
                        • An InfoTable property should never be directly modified, but instead a copy of the property created in a custom service to then perform any operations upon and then it can be written back to the existing InfoTable property upon completion of the service
                      • The following two links provide more information on InfoTables

                       

                      It is quite easy to add data entries into a DataTable(Remember DataTable has primary key like what we have in database table).

                      You could use like this:

                      var values = Things["DT1"].CreateValues();//DT1 is an entity with Thing Template of DataTable

                      values.parentname = undefined; // you could add any of your data field; parentName, name ,id is just my example
                      values.name = undefined; //STRING
                      values.id = undefined; //INTEGER [Primary Key]

                      var params = {
                      sourceType: undefined /* STRING */,
                      values: values /* INFOTABLE*/,
                      location: undefined /* LOCATION */,
                      source: undefined /* STRING */,
                      tags: undefined /* TAGS */
                      };

                      // result: STRING
                      var id = Things["DT1"].AddDataTableEntry(params);

                       

                      Please let me know if you have any more questions.

                       

                      Thanks,

                       

                      Br,

                      Anna

                • Re: Get tags from Kepware -> add them to a thing in Thingworx
                  ppradhan Apprentice

                  Why do you need to connect using javascript? if you can connect the kepware tags to proprties of things directly. you are aware of it right?