Hi ,
I want to be able to connect a fetch statement on the disabling or enabling of a node. Is there something similar like oneditprepare or oneditsave where I can check if this node is been disabled or enabled?
My asset management system is registering if a certain "asset" is active or inactive. It would be super sweet if I could connect the enable , disable functionality in stead of making another dropdown menu for it.
I understand that the fetch action only gets executed on deploy but that's ok for me.
Can you be more specific where you want to check the status of a node. e.g. Do you have a plugin? You can check the status in oneditsave. (By status I mean enabled/disabled).
The variables from the settings.js file are fetched using:
oneditprepare: function() {
const node = this;
// Fetch settings
$.getJSON('settings', function(settings) {
try {
console.log(settings.functionGlobalContext);
// Check if UUID exists in settings
const uuid = (settings.functionGlobalContext && settings.functionGlobalContext.uuid) ? settings.functionGlobalContext.uuid : 'default-uuid';
// Use UUID
console.log('UUID:', uuid);
} catch (error) {
console.error('Error fetching settings:', error);
}
});
// Define API URLs for single source of truth configuration but also provide a backup for local testing and situations where the cloud is not available
// Find the active tab name by inspecting the DOM
const activeTabElement = $('.red-ui-workspace-active');
node.processId = activeTabElement.attr('data-id') || activeTabElement.text();
node.configUrls = assetUtils.getAssetVariables();
console.log("assetLocationId", node.locationId);
console.log("assetProcessId", node.processId);
console.log("configUrls", node.configUrls);
//make node specific uuid
node.uuid = uuid+node.id;
console.log(`------------ Preparing to edit measurement node with uuid : ${node.uuid}------------`);
Are you trying to read runtimeState directly from settings? That's a static prop only essentially enabling this API call: GET /flows/state : Node-RED that will tell you if flows are running or not.
If you'd be interested in runtimeState you'd have to set this prop to true in settings.json but then use API to get the state value.
But this is not something you want I presume. I also have a bit of trouble understanding what exactly are you trying to achieve?
You have a custom node and you want to detect if that node gets disabled? or if some other node gets disabled?
Yes I have a custom node and I want this node to see if it gets disabled or enabled and do some kind of action when it is.
On top of that I want to access a global declared static variable from inside the settings.js and read it in my html environment of my custom node. I got as far as being able to access the variable in my .js file by calling:
const globalContext = this.context().global;
const locationId = globalContext.get("locationId") || "No location ID set";
// Store it in the node instance?
config.locationId = locationId;
however when I access this in my HTML file under this.locationId it remains undefined.
So if someone can refer me to a manual on how to get those values please do.
This won't work, your node at runtime (server) part and your node in editor are different objects. They don't share properties. So if you assign something to node object serves side it's not available on node object in browser.
Easiest is to create an API endpoint in your server side node code and and fetch required data from client side.
Check core nodes for this approach, e.g. debug node.
How do I access this then from within my oneditprepare function its not clear from your snippet.
There is no prop called this.d
Ah I assume this is from the output from the json structure. I tried to access d from within the html file but helas no success.
Ive done this differently btw. Im importing a custom settings file into the html to fetch and build my uuid etc...
This doesnt then load on runtime but I dont need it to. All my nodes create and fetch the needed vars when registered / prepared which is also fine.
So in a sense it works like suggested through a fetch but not using the node red core method. I find it too rigid/complex.
In the end im using this:
<script type="module">
import * as menuUtils from "/generalFunctions/helper/menuUtils.js";
import * as assetUtils from "/generalFunctions/helper/assetUtils.js";
import * as projectSpecificSettings from "/generalFunctions/settings/projectSpecificSettings.js";
RED.nodes.registerType("measurement", {
category: "digital twin",
color: "#e4a363",