Skip to main content
1-Visitor
March 13, 2020
Solved

How to reference data table, get specific column value, and use as entry into a separate infotable

  • March 13, 2020
  • 1 reply
  • 3363 views

Hi,

For a current customer I am trying to implement a service that will record the Fault messages of the machine.

I've set up an infotable property on the asset that would house the recorded faults.

I've also set up a data table holding the fault code reference document that has a numerical code and string for each fault.

 

What I need to do, is when an Alert on the faulted PLC tag is triggered, to get the numerical code from a seperate PLC tag, reference that code in the data table, get the string equivalent, then add a row with all that information to my asset fault history infotable property.

 

I cannot get my javascript code to work, I'll paste below what I have currently, I am wondering now if it is easier to use data tables for both tables listed above or if this set up should work?

 

To clarify, I am using a configured Alert on the Faulted property (boolean) to trigger a subscription with the following code:

 

var PLCFaultCode = me.Current_Fault_Code;
var propertyString = "Fault_History_Table";

var query1 = {
"filters": {
"type": "EQ",
"fieldName": "FaultCode",
"value": PLCFaultCode
}
};

var params1 = {
t: Things["Mahle_GapGrind_FaultMessages_DataTable"] /* INFOTABLE */,
query: query1 /* QUERY */
};

// result: INFOTABLE
var result2 = Resources["InfoTableFunctions"].Query(params1);

me.AddInfoTableValueStreamEntry({
propertyName: propertyString /* STRING */,
value: result2 /* INFOTABLE */,
timestamp: undefined /* DATETIME */,
});

 

Any help greatly appreciated!

Best answer by cmorfin

Hi @ateed 

 

From the code you seem to be passing a dataTable as parameter t, that is then passed to Resources["InfoTableFunctions"].Query(params1);

This t parameter should be an infotable not a data table.

You can maybe test 

var params1 = {
t: Things["Mahle_GapGrind_FaultMessages_DataTable"].QueryDataTableEntries({
maxItems: undefined /* NUMBER */,
query: undefined /* QUERY */,
values: undefined /* INFOTABLE */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
}) /* INFOTABLE */,
query: query1 /* QUERY */
};

 

instead, just to test that it goes further.

You can then check with service QueryInfoTablePropertyHistory if you see the update (I do)

 

Thanks

Hope this helps

Christophe

 

1 reply

cmorfin19-TanzaniteAnswer
19-Tanzanite
March 16, 2020

Hi @ateed 

 

From the code you seem to be passing a dataTable as parameter t, that is then passed to Resources["InfoTableFunctions"].Query(params1);

This t parameter should be an infotable not a data table.

You can maybe test 

var params1 = {
t: Things["Mahle_GapGrind_FaultMessages_DataTable"].QueryDataTableEntries({
maxItems: undefined /* NUMBER */,
query: undefined /* QUERY */,
values: undefined /* INFOTABLE */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
}) /* INFOTABLE */,
query: query1 /* QUERY */
};

 

instead, just to test that it goes further.

You can then check with service QueryInfoTablePropertyHistory if you see the update (I do)

 

Thanks

Hope this helps

Christophe

 

ateed1-VisitorAuthor
1-Visitor
March 17, 2020

Yes, so my problem was mixing data tables and infotables like you pointed out. I ended up changing the code quite a lot and it's working now, thanks for the help!