Yes, I found that, but it doesn't solve the problem. I'm trying to create and populate an object and put it in global from within a custom node and then access it from a function node. I have put together a simplified test case - maybe from that you can point me in the right direction.
Just click the inject node and it should dump what it sees to the debug panel.
The test flow is: [{"id":"354fd111.cab02e","type":"inject","z":"784c8074.87b38","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":120,"y":200,"wires":[["b89849bf.4767b8"]]},{"id":"b89849bf.4767b8","type":"function","z":"784c8074.87b38","name":"Dump testObj","func":"var testObj = global.get('testObj');\nnode.warn('test object:', util.inspect(testObj));\nif (testObj === undefined) {\n node.warn('test object undefined');\n}\nnode.warn('test object type:', typeof testObj);\nnode.warn('test object toString:', testObj.toString());\nreturn null;","outputs":1,"noerr":0,"x":350,"y":200,"wires":[[]]}]
The html is:
<script type="text/javascript">
RED.nodes.registerType('test',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""}
},
inputs:1,
outputs:1,
icon: "file.png",
label: function() {
}
});
</script>
<script type="text/x-red" data-template-name="test">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="test">
<p>This node sets the Content-Type header to match the msg.filename</p>
</script>
and the js is:
module.exports = function(RED) {
function testNode(config) {
RED.nodes.createNode(this,config);
var node = this;
var testObj = {};
testObj.a = 'a';
testObj.b = 'b';
this.context.global.set('testObj', testObj);
this.on('input', function(msg) {
msg.payload = 'test';
});
}
RED.nodes.registerType("test", testNode);
}