Create json object in flow

Hi good day, I am trying to create object in json format, therefore i can call within flow. The issue is in context data (in flow columns its doesn't appear). i am pretty sure all parameters content data. May i know why?

var stcal = {
    "line_name"     : json[0].lineName,
    "line_No"       : json[0].line,
    "currpct"       : json[0].curPercentage,
    "SHTPLAN"       : json[0].shiftPlan,
    "PinStatus"     : json[0].OutputPin,        //from php input
    "STActual"      : json[0].stActual,         //STActual    
    "SHTActual"     : json[0].shiftActual,      //Shift Actual
    "remark"        : json[0].remarks
}
flow.set('stcal',stcal);

Hi @tramanah

Can you provide some more details? There's nothing inherently wrong with the code you've shared. But without knowing what your json variable is, where it comes from and what it contains, it's hard to suggest anything.

flow: - Update STCAL


var Deviceid = flow.get('Deviceid');

msg.topic = "Select *from stcalA where deviceID = '"+ Deviceid +"'";

return msg;


flow : - stcalA json


var obj = msg.payload;
var json = JSON.parse(obj);
var Deviceid = flow.get('Deviceid');
var SHTActual = flow.get('SHTActual')||0;
var STActual = flow.get('STActual')||0;

var resetcounter = flow.get('resetcounter');
var amenddata = flow.get('amenddata');

var Indata = flow.get('Indata'); //![stcal|637x500]
if(json[0].OutputPin === 'RST MASTER'){
resetcounter = 1;
amenddata = 0;
SHTActual = 0;
STActual = 0;
Indata.ATCounter = 0;
Indata.STCounter = 0;
json[0].OutputPin = Indata.PinStatus;

flow.set('Indata.ATCounter',Indata.ATCounter);
flow.set('Indata.STCounter',Indata.STCounter);

}
else if(json[0].OutputPin === 'AMEND'){
resetcounter = 0;
if(amenddata === 1){
amenddata = 0;
json[0].OutputPin = Indata.PinStatus;
}
else {amenddata = 1;}

SHTActual   = json[0].shiftActual;
STActual    = json[0].stActual;
Indata.ATCounter  = json[0].SHTActual;
Indata.STCounter  = json[0].STActual;
json[0].OutputPin = Indata.PinStatus;

flow.set('Indata.ATCounter',Indata.ATCounter);
flow.set('Indata.STCounter',Indata.STCounter);

}
else{
resetcounter = 0;
amenddata = 0;
var status = flow.get('Indata.ATCounter')
if (!status){
SHTActual = json[0].shiftActual;
STActual = json[0].stActual;
}
else{
SHTActual = flow.get('Indata.ATCounter');
STActual = flow.get('Indata.STCounter');
}
if(Indata.PinStatus){
json[0].OutputPin = Indata.PinStatus;
}
else{json[0].OutputPin = 'Not_Assigned';}
}

flow.set('resetcounter',resetcounter);
flow.set('amenddata',amenddata);

flow.set('SHTActual',SHTActual);
flow.set('STActual',STActual);

var stcal = {
"line_name" : json[0].lineName,
"line_No" : json[0].line,
"currpct" : json[0].curPercentage,
"SHTPLAN" : json[0].shiftPlan,
"PinStatus" : json[0].OutputPin, //from php input
"STActual" : json[0].stActual, //STActual
"SHTActual" : json[0].shiftActual, //Shift Actual
"remark" : json[0].remarks
}

flow.set('stcal',stcal);

return msg;*******************************************************************************************************

Note: In fact all the tab's are enable while testing in progress.

Please read this post How to share code or flow json and edit your post to fix the formatting of the code you've shared.

Can you also explain in more detail what behaviour you want? We can't reverse engineer 50+ lines of code and guess what you want it to do.

You should also add a debug to the output of JSON node to show us what the data actually looks like.

I did isolate the nodes and just focus on node which create json object, seems its working now. Its shows my coding error in another nodes. I will look into that.

Thank you.