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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

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

nquirindongo
9-Granite

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.

1 ACCEPTED SOLUTION

Accepted Solutions
AnnaAn
13-Aquamarine
(To:nquirindongo)

Hi nquirindongo,

Are you using ThingWorx 7.4 and connect directly with Kepware? If so it's much easier to connect kepware to ThingWorx and you will find it very easy to bind Tags(In Thingworx 7.4, you could discover the tag directly from new-generation composer), and you do not need to bind it with Browse Items or AddItems. Here is how to connect Kepware to ThingWorx in Help Center. Keep in mind ThingWorx 7.4 or higher is needed, and KEPServerEX 6.1 or higher is needed.

Let me know if this could give you any hint or any questions.

Thanks,

Br,

Anna

View solution in original post

12 REPLIES 12
AnnaAn
13-Aquamarine
(To:nquirindongo)

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;

 

                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

AnnaAn
13-Aquamarine
(To:nquirindongo)

Hi Nelson,

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

Thanks,

Br,

Anna

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);
}

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?

AnnaAn
13-Aquamarine
(To:nquirindongo)

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

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?

What do you mean? Manually? If so, will not work for me.

I'm looking for a solution where I can have a mash up or dashboard where I can select/deselect the channels from the kepserver.

AnnaAn
13-Aquamarine
(To:nquirindongo)

Hi nquirindongo,

Are you using ThingWorx 7.4 and connect directly with Kepware? If so it's much easier to connect kepware to ThingWorx and you will find it very easy to bind Tags(In Thingworx 7.4, you could discover the tag directly from new-generation composer), and you do not need to bind it with Browse Items or AddItems. Here is how to connect Kepware to ThingWorx in Help Center. Keep in mind ThingWorx 7.4 or higher is needed, and KEPServerEX 6.1 or higher is needed.

Let me know if this could give you any hint or any questions.

Thanks,

Br,

Anna

No... I'm still with ThingWorx 7.1 and KEPServer EX 6.0

In the process to upgrade both.

AnnaAn
13-Aquamarine
(To:nquirindongo)

Hi nquirindongo,

Glad to know you are trying to upgrade both.

Please keep me updated or let me know if any issue you may have.

Thank you,

Br,

Anna

AnnaAn
13-Aquamarine
(To:nquirindongo)

Dear quirindongo,

How about your issue? Is it resolved or still have any issue? Please let us know of your progress.

Thanks,

Br,

Anna

Hi Anna,

We put that effort on hold until thingworx 8.0 is release. In the meantime I have been playing around with the other capabilities of thingworx 7

I'll keep you posted.

Regards,

Nelson Q

Top Tags