Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
I am writing a custom service to a Data Table to update the data table with the count and summation data from another data table.
Input to the service is an infotable DowntimeData which is the infotable from QueryDataTableEntries service of another data table and below is the javascript code. When executed the Error message as in the subject is displayed.
// result: INFOTABLE dataShape: ""
var Category = Things["DowntimeCategoryDataTable"].GetDataTableEntries();
for(index = 0; index < Category.rows.length; index++) {
DowntimeCategory = Category.rows[index].DowntimeCategory;
// Provide your filter using the format as described in the help topic "Query Parameter for Query Services"
let query = {
"filters": {
"type": "EQ",
"fieldName": "DowntimeCategory",
"value": DowntimeCategory
}
};
var params = {
t: DowntimeData /* INFOTABLE */,
query: query
};
var result1 = Resources["InfoTableFunctions"].Query(params);
DowntimeCount = result1.rows.length;
DowntimeDuration = 0;
for(x = 0; x < result1.rows.length; x++) {
DowntimeDuration = DowntimeDuration + result1.rows[x].DowntimeDuration;
}
// DowntimeParetoTrial entry object
var newEntry = new Object ();
newEntry.DowntimeCategory = DowntimeCategory; // STRING [Primary Key]
newEntry.DowntimeCount = DowntimeCount; // INTEGER
newEntry.DowntimeDuration = DowntimeDuration; // NUMBER
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(DowntimeParetoTrial)
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "DowntimeParetoTrial"
});
result.AddRow(newEntry);
}
Solved! Go to Solution.
I changed the output to a Data Table and updated the requirement in the same to get my desired output and it worked (code below). Not sure what your solution was.
var Category = Things["ReworkCategoryDataTable"].GetDataTableEntries();
for(index = 0; index < Category.rows.length; index++) {
ReworkCategory = Category.rows[index].PartsReworkedCategory;
// Filtering infotable based on Category
let query = {
"filters": {
"type": "EQ",
"fieldName": "PartsReworkedCategory",
"value": ReworkCategory
}
};
var params = {
t: ReworkData /* INFOTABLE */,
query: query
};
var result1 = Resources["InfoTableFunctions"].Query(params);
// Calculating Count
ReworkEntryCount = result1.rows.length;
PartsReworked = 0;
for(x = 0; x < result1.rows.length; x++) {
PartsReworked = PartsReworked + result1.rows[x].PartsReworked;
}
// tags:TAGS
let tags = new Array();
// values:INFOTABLE(Datashape: ReworkParetoDataShape)
let values = Things["ReworkParetoDataTable"].CreateValues();
values.PartsReworked = PartsReworked; // INTEGER
values.ReworkedCategory = ReworkCategory; // STRING [Primary Key]
values.PartsReworkEntryCount = ReworkEntryCount; // INTEGER
// location:LOCATION
let location = {
latitude: 0,
longitude: 0,
elevation: 0,
units: "WGS84"
};
let params1 = {
tags: tags,
source: me.name,
values: values,
location: location
};
// AddOrUpdateDataTableEntry(tags:TAGS, source:STRING("me.name"), values:INFOTABLE(ReworkParetoDataTable), location:LOCATION):STRING
let id = Things["ReworkParetoDataTable"].AddOrUpdateDataTableEntry(params1);
}
Most likely you are running into a null value somewhere. Else perhaps the value you are generating doesn't have the correct basetype.
I would log out temporarily what your row values are as you loop to check and see what is actually happening.
I changed the output to a Data Table and updated the requirement in the same to get my desired output and it worked (code below). Not sure what your solution was.
var Category = Things["ReworkCategoryDataTable"].GetDataTableEntries();
for(index = 0; index < Category.rows.length; index++) {
ReworkCategory = Category.rows[index].PartsReworkedCategory;
// Filtering infotable based on Category
let query = {
"filters": {
"type": "EQ",
"fieldName": "PartsReworkedCategory",
"value": ReworkCategory
}
};
var params = {
t: ReworkData /* INFOTABLE */,
query: query
};
var result1 = Resources["InfoTableFunctions"].Query(params);
// Calculating Count
ReworkEntryCount = result1.rows.length;
PartsReworked = 0;
for(x = 0; x < result1.rows.length; x++) {
PartsReworked = PartsReworked + result1.rows[x].PartsReworked;
}
// tags:TAGS
let tags = new Array();
// values:INFOTABLE(Datashape: ReworkParetoDataShape)
let values = Things["ReworkParetoDataTable"].CreateValues();
values.PartsReworked = PartsReworked; // INTEGER
values.ReworkedCategory = ReworkCategory; // STRING [Primary Key]
values.PartsReworkEntryCount = ReworkEntryCount; // INTEGER
// location:LOCATION
let location = {
latitude: 0,
longitude: 0,
elevation: 0,
units: "WGS84"
};
let params1 = {
tags: tags,
source: me.name,
values: values,
location: location
};
// AddOrUpdateDataTableEntry(tags:TAGS, source:STRING("me.name"), values:INFOTABLE(ReworkParetoDataTable), location:LOCATION):STRING
let id = Things["ReworkParetoDataTable"].AddOrUpdateDataTableEntry(params1);
}
Hi @AK_9980944.
Since you found your own solution, please mark your last post as the Accepted Solution for the benefit of others with the same question.
Regards.
--Sharon