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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Error in: Message ::Unable To Convert From org.mozilla.javascript.UniqueTag to INFOTABLE

AK_9980944
7-Bedrock

Error in: Message ::Unable To Convert From org.mozilla.javascript.UniqueTag to INFOTABLE

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

}

ACCEPTED SOLUTION

Accepted Solutions

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


}

View solution in original post

3 REPLIES 3
PaiChung
22-Sapphire I
(To:AK_9980944)

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


}

slangley
23-Emerald II
(To:AK_9980944)

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

Announcements


Top Tags