Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X
Hello everyone!!
I'm trying to create a demo having data in csv(or json) format.
I would like to import data's file in the composer, parse it and see data in a mashup with a grid.
Also i would like to create a stream that show me (in the meshup) the parameter's trend.
I created a thing with a repository template (because the file is in C:/ThingworxStorage/repository) but when i try the service loadJSON anything appeare to me.
Can anyone help me??
Thank's!!
Solved! Go to Solution.
you need to hit the save button for the service after creating it before you can hit the execute, that's the classic error you see, if you haven't done that.
Maurizio,
Here is an example of pulling data from a csv file stored in a repository and then outputting it as an infotable in a service.
var params = {
path: "RPTM.csv" /* STRING */,
columnMappings: "Location;StartTime;EndTime;ProductCode;CasesProduced;PerHourCWS;CWS;Efficiency"/* STRING */,
hasHeader: true /* BOOLEAN */,
longitudeField: undefined /* NUMBER */,
dateFormat: undefined /* STRING */,
fileRepository: "RPTMFileRepository"/* THINGNAME */,
latitudeField: undefined /* NUMBER */,
fieldDelimiter: "," /* STRING */,
stringDelimiter: "\"" /* STRING */,
dataShape: "RPTMImport" /* DATASHAPENAME */
};
// result: INFOTABLE
var rptmData = Resources["CSVParserFunctions"].ReadCSVFile(params);
var params = {
infoTableName : "InfoTable",
dataShapeName : "RPTM"
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(RPTM)
var modifiedData = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
//translating the date fields in csv to date fields in ThingWorx
for each (var row in rptmData.rows) {
var startTime = new Date(row.StartTime);
var endTime = new Date(row.EndTime);
row.StartTime = startTime;
row.EndTime = endTime;
modifiedData.AddRow({
Location: row.Location,
StartTime: startTime,
EndTime: endTime,
ProductCode: row.ProductCode,
CasesProduced: row.CasesProduced,
PerHourCWS: row.PerHourCWS,
CWS: row.CWS,
Efficiency: row.Efficiency,
Baseline: 100.00
});
}
result = modifiedData;
Thanks,
Keri
Thank's Kery!
I create a service with your script modificate with my name's file and called it GetDataCSV but when i test the servite appear:
Error executing service
Invalid service name: GetDataCSV
I try to change name service but the error it's the same.
Have you got any idea??
Thank's very much!!
you need to hit the save button for the service after creating it before you can hit the execute, that's the classic error you see, if you haven't done that.
thank's very much!
now the problem is:
Error executing service
Wrapped java.lang.Exception: Unable To Convert From java.lang.String to NUMBER Cause: Unable To Convert From java.lang.String to NUMBER
what does your data look like, it sounds like it thinks that there is a value in your number field that is coming across as a string
You should see this as well I am getting access denied error while Reading CSV file