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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

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

ateed
4-Participant

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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
cmorfin
19-Tanzanite
(To:ateed)

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

 

View solution in original post

2 REPLIES 2
cmorfin
19-Tanzanite
(To:ateed)

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

 

ateed
4-Participant
(To:cmorfin)

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!

Top Tags