Skip to main content
Jul 19, 2018 4:13 PM UTC
Solved

JSON in repository to InfoTable is returning nothing

Hi all,

 

My code to convert a JSON file into a Infotable is returning only the columns title and nothing else as you can see at image below:

Believe me, I read all PTC articles, cases, and topics here in this community and tried all suggestion, but it simply does not work.

 

So, can anyone help me with this? Below is the code:

var params = {
	proxyScheme: undefined /* STRING */,
	headers: undefined /* JSON */,
	ignoreSSLErrors: true /* BOOLEAN */,
	useNTLM: undefined /* BOOLEAN */,
	workstation: undefined /* STRING */,
	useProxy: undefined /* BOOLEAN */,
	withCookies: undefined /* BOOLEAN */,
	proxyHost: undefined /* STRING */,
 url: "http://localhost:9090/Thingworx/FileRepositories/TrainingRepository/JSON/GetMachineGreen_Original.json" /* STRING */,
	timeout: undefined /* NUMBER */,
	proxyPort: undefined /* INTEGER */,
	password: undefined /* STRING */,
	domain: undefined /* STRING */,
	username: undefined /* STRING */
};

// result: JSON
var data = Resources["ContentLoaderFunctions"].GetJSON(params);


var params = {
	infoTableName: "InfoTable" /* STRING */,
	dataShapeName: "CobotDataShape" /* DATASHAPENAME */
};

// result: INFOTABLE
var CobotInfoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var tableLength = CobotInfoTable.rows.length;

for (var x = 0; x < tableLength; x++) {
	var row = CobotInfoTable.rows[x];
	//Your code here
	CobotInfoTable.AddRow({
 				AddAdmin:data.AddAdmin,
 AirPressureStatus:data.AirPressureStatus,
 BaseFPLSealantSpeed:data.BaseFPLSealantSpeed,
 BaseWACLSealantSpeed:data.BaseWACLSealantSpeed,
 CalculatedFPLVel:data.CalculatedFPLVel,
 CalculatedWACLVel:data.CalculatedWACLVel,
 CancelJob:data.CancelJob,
 CurrentSiliconBarcode:data.CurrentSiliconBarcode,
 DisplayStopReason:data.DisplayStopReason,
 EnabledTasks:data.EnabledTasks,
 EventErrors:data.EventErrors,
 EventInfos:data.EventInfos,
 EventWarnings:data.EventWarnings,
 ExtEStop:data.ExtEStop,
 FPLACreated:data.FPLACreated,
 FPLAExpected:data.FPLAExpected,
 FPLAMonth:data.FPLAMonth,
 FPLBCreated:data.FPLBCreated,
 FPLBExpected:data.FPLBExpected,
 FPLBMonth:data.FPLBMonth,
 FPLIdealCycleTime:data.FPLIdealCycleTime,
 FPLSiliconSpeed:data.FPLSiliconSpeed,
 FastenerDuration:data.FastenerDuration,
 Humidity:data.Humidity,
 HumidityMax:data.HumidityMax,
 HumidityMin:data.HumidityMin,
 IdleTime:data.IdleTime,
 LimitsOverride:data.LimitsOverride,
 LocalEStop:data.LocalEStop,
 LogoutOperator:data.LogoutOperator,
 MaxFPLQty:data.MaxFPLQty,
 MaxWACLQty:data.MaxWACLQty,
 NewJob:data.NewJob,
 RemoveAdmin:data.RemoveAdmin,
 ResetEnabled:data.ResetEnabled,
 RobotHeartbeat:data.RobotHeartbeat,
 RobotStoppage:data.RobotStoppage,
 ScanAddAdmin:data.ScanAddAdmin,
 ScanOperator:data.ScanOperator,
 ScanPartBarcode:data.ScanPartBarcode,
 ScanRemoveAdmin:data.ScanRemoveAdmin,
 ScanSiliconBarcode:data.ScanSiliconBarcode,
 ShiftAvailability:data.ShiftAvailability,
 ShiftPerformance:data.ShiftPerformance,
 SiliconChange:data.SiliconChange,
 SiliconOverride:data.SiliconOverride,
 SiliconPurge:data.SiliconPurge,
 SiliconPurgeAllowed:data.SiliconPurgeAllowed,
 SiliconRemaining:data.SiliconRemaining,
 SiliconReset:data.SiliconReset,
 StartEnabled:data.StartEnabled,
 StopEnabled:data.StopEnabled,
 Temperature:data.Temperature,
 TemperatureMax:data.TemperatureMax,
 TemperatureMin:data.TemperatureMin,
 TemperatureOverride:data.TemperatureOverride,
 TotalCycleTime:data.TotalCycleTime,
 ViscosityFunctionBaseTemp:data.ViscosityFunctionBaseTemp,
 ViscosityFunctionC:data.ViscosityFunctionC,
 ViscosityFunctionX1:data.ViscosityFunctionX1,
 ViscosityFunctionX2:data.ViscosityFunctionX2,
 WACLACreated:data.WACLACreated,
 WACLAExpected:data.WACLAExpected,
 WACLAMonth:data.WACLAMonth,
 WACLBCreated:data.WACLBCreated,
 WACLBExpected:data.WACLBExpected,
 WACLBMonth:data.WACLBMonth,
 WACLIdealCycleTime:data.WACLIdealCycleTime,
 WACLSiliconSpeed:data.WACLSiliconSpeed,
 PowerConsumption:data.PowerConsumption,
 MonthlyPowerTarget:data.MonthlyPowerTarget,
 MonthlyAirConsumption:data.MonthlyAirConsumption,
 				PrimaryKey:2});
}

result = CobotInfoTable;

 

The JSON file has no arrays or group or something like this, it is just straight forward with objects.

 

Thanks in advance!

 

Best Regards,

Felipe Duarte

 

 

 

 

vxavierAnswer
Jul 20, 2018 1:25 PM UTC

I was trying with this JSON File, Colors.JSON:

[
	{
		"color": "red",
		"value": "#f00"
	},
	{
		"color": "green",
		"value": "#0f0"
	},
	{
		"color": "blue",
		"value": "#00f"
	},
	{
		"color": "cyan",
		"value": "#0ff"
	},
	{
		"color": "magenta",
		"value": "#f0f"
	},
	{
		"color": "yellow",
		"value": "#ff0"
	},
	{
		"color": "black",
		"value": "#000"
	}
]

I tried this code and this worked for me. I have downloaded and installed the Parsley Advanced Parsing Extension

 

 

var params = {
	path: "/Colors.JSON" /* STRING */
};

// Get the JSON file in the System Repository, return type is JSON
var Content = Things["SystemRepository"].LoadJSON(params);


var params = {
	minDateMilliseconds: undefined /* LONG */,
	dateFormat: undefined /* STRING */,
	json: Content /* JSON */,
	dataShape: "DataShape1" /* DATASHAPENAME */
};

// result: INFOTABLE
var result = Resources["Parsley"].ParseJSON(params).array;

My Output was:

 

myresult.png

 

11 replies

Jul 19, 2018 5:40 PM UTC

Hello there,

 

You are using FOR in an empty table. You have to iterate in the JSON data, and not in your new empty infotable.

 

Best Regards,

Vinicius.

DuartefeAuthor
Jul 19, 2018 11:12 PM UTC
Hi Vinicius,

Thanks for reply.

I have tried used the data but in this case it returns that length is not defined.
Jul 19, 2018 5:59 PM UTC

Also, you cant try to use the snippet FromJSON, that converts JSON into an info table:

 

var params = {
	json: undefined /* JSON */
};

// result: INFOTABLE
var result = Resources["InfoTableFunctions"].FromJSON(params);

 

DuartefeAuthor
Jul 19, 2018 11:15 PM UTC
I also tried with FromJSON and could not load anything at all. Believe I tried everything.
Currently I am suspecting about the url. Maybe I should use another way to explicit the path for the json file.

Any idea?
Jul 20, 2018 12:34 PM UTC

I test this FromJson and this doesn't worked for me at all, I am trying another methods. 

 

To see if this get method is working fine, try to set the output as JSON, and make the result = data.