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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

convert data into number in datatable

xiaoqw
15-Moonstone

convert data into number in datatable

here is my coding which I want to do calculation using datatable data. output should be "NUMBER". but now result is NaN. Could someone help me figure it out?

 

var query =
{
"filters": {
"type": "And",
"filters": [
{
"type": "EQ",
"fieldName": "Department",
"value": "Milk"
},
{
"type": "EQ",
"fieldName": "Kategory",
"value": "Production Volume"
}
]
}
};

var output = Resources["InfoTableFunctions"].RenameField({
t: Resources["InfoTableFunctions"].Aggregate({
t: me.QueryDataTableEntries({ maxItems: undefined,
query: query,
values:undefined,
source: undefined,
tags:undefined
}),
columns: 'value',
aggregates: 'SUM',
groupByColumns: 'value'
}),
from: "SUM_value",
to: "value"
});

var result = parseInt(output/10000);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaiChung
22-Sapphire I
(To:xiaoqw)

 

var result = parseInt(output/10000);

It looks like you are trying to divide the whole infotable? maybe

var result = parseInt(output.value/10000);

 BTW it seems redundant to rename the field, not sure if you are trying to use the infotable somewhere else as well.

View solution in original post

5 REPLIES 5
PaiChung
22-Sapphire I
(To:xiaoqw)

 

var result = parseInt(output/10000);

It looks like you are trying to divide the whole infotable? maybe

var result = parseInt(output.value/10000);

 BTW it seems redundant to rename the field, not sure if you are trying to use the infotable somewhere else as well.

xiaoqw
15-Moonstone
(To:PaiChung)

Thank you for your help. it works!!!

tmisner
16-Pearl
(To:xiaoqw)

Hello Tracy,

 

Thank you for reaching out on the ThingWorx Developers Community.

 

I did some quick testing with the code provided and I believe you can achieve the desired results by changing the last line to the following:

var result = parseInt(output.value/10000);

 

When you call for output only the return is an Infotable. If you call for output.value you specifically get the single number from the value field.

 

Please let me know if this is helpful.

 

Regards,

Tyler Misner

ThingWorx Technical Support Engineer

Looks like @PaiChung has already replied on this one.

xiaoqw
15-Moonstone
(To:tmisner)

Anyway thank you for you testing my code!! And thank you Thingworx Developers Community

Top Tags