Function 4 goes:
global.set("TRIGGER",msg.payload);
var res = global.get('LENGTH');
var res1 = global.get('CABLE_DESCRIPTION');
var res2 = global.get('FAULT_STRING');
var res3 = global.get('TRIGGER')
if(res3===true){
msg.payload = "res"+"res1"+"res2";
}
else{
return msg[null];
}
Function 1 till 3 remain same with change in definition of global variable name.
global.set("LENGTH",msg.payload);
return msg;
What i am trying to achieve here if trigger goes high then capture the data and display it !!
You are trying to construct the msg.payload from strings, and not the variables that you created earlier...
example - res is a variable, "res" is a string
What does that line do? I don't think it is valid javascript, but perhaps it is some subtle syntax that I have not met so far. I wonder whether you meant to say return null
You are calling the global variables correctly, but when you are trying to create the msg.payload you are referring to the variables as strings, because you have added speech marks around the variable's names.
Are res, res1 and res2 numbers because you seem to be adding (+) their values together.
If res, res1 and res2 are string values, then maybe && instead of +
Yes res and res1 are numbers, res 3 is string, tried changing it but no luck yet
global.set('TRIGGER',msg.payload);
var res = global.get('LENGTH');
var res1 = global.get('CABLE_DESCRIPTION');
var res2 = global.get('FAULT_STRING');
var res3 = global.get('TRIGGER')
//var rest = msg.payload;
@Colin how can we return the message with combination of String and variable together ?
var res = global.get('LENGTH');
var res1 = global.get('CABLE_DESCRIPTION');
var res2 = global.get('FAULT_STRING');
var trig = global.get('TRIGGER')
if(trig===false)
{
msg.payload = res;
return msg;
}
else
{
return msg[null];
}
Can you clarify exactly what you want the function to return? You are getting four values from context. Describe in words what you want the result to be.
Right at the start of this thread, you had the code:
global.set("TRIGGER",msg.payload);
var res = global.get('LENGTH');
var res1 = global.get('CABLE_DESCRIPTION');
var res2 = global.get('FAULT_STRING');
var res3 = global.get('TRIGGER')
if(res3===true){
msg.payload = "res"+"res1"+"res2";
}
else{
return msg[null];
}
As Paul pointed out, the line:
msg.payload = "res"+"res1"+"res2";
Will result in msg.payload having the value "resres1res2". If you meant to join those three variables together, you should do:
msg.payload = res+res1+res2;
You will also need a return msg at the end so it returns the message.
That doesn't help explain what format you want it to be in. I have assumed you want it to return a message with the three values joined together as a string.
If instead you want it to return a message with an object payload with the three separate values in it, you could do: