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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

JSON in repository to InfoTable is returning nothing

Duartefe
11-Garnet

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

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
vxavier
13-Aquamarine
(To:Duartefe)

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

 

View solution in original post

11 REPLIES 11
vxavier
13-Aquamarine
(To:Duartefe)

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.

Hi Vinicius,

Thanks for reply.

I have tried used the data but in this case it returns that length is not defined.
vxavier
13-Aquamarine
(To:Duartefe)

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

 

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?
vxavier
13-Aquamarine
(To:Duartefe)

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.

 

vxavier
13-Aquamarine
(To:Duartefe)

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

 

vxavier
13-Aquamarine
(To:vxavier)

And, Without using the Parse Extension:

 

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

// result: JSON
var Content = Things["SystemRepository"].LoadJSON(params);


var params = {

infoTableName: undefined /* STRING */,

dataShapeName: "DataShape1" /* DATASHAPENAME */

};

// result: INFOTABLE

var jsonTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);



for(i in Content.array){
    jsonTable.AddRow({color:Content.array[i].color, value:Content.array[i].value});
}

//}

result = jsonTable;

So now, it is returning File Does not Exist. I got this error before as well.

 

Please tell me, where you store the json File?

vxavier
13-Aquamarine
(To:Duartefe)

In the folder that are your ThingWorx files:

*\ThingworxStorage\repository\SystemRepository

Hi Vinicius,

 

Now it works using the extension but I just have one line I took of the .array.

So, the code is that for future reference:

var params = {
    path: "GetMachineGreen_Original.json"
};

var Content = Things["SystemRepository"].LoadJSON(params);

var params = {
    json: Content,
    dataShape: "CobotDataShape"
};

var result = Resources["Parsley"].ParseJSON(params);

 

Now, many thanks with you quick replies and effort!

 

Best Regards,

Felipe Duarte

vxavier
13-Aquamarine
(To:Duartefe)

You're welcome Felipe.

 

The .array was because my JSON was structured as array JSON.

 

Best Regards,

Vinicius Xavier.

Top Tags