sorry for posting this, but I need some help and another pair of eyes. I must admit that everything that I have found here on stackoverflow, splunk docs and splunk community answers, and of course tried, it failed on me.
What I want to achieve is to read from a custom config file (file details below) and get that result out to be used in other part of the code for a double check.
Conf file details:
name config.conf,
the stanza is named download,
the property is called version which may have value of new or old.
The code is:
define(["jquery", "react", "splunkjs/mvc", "splunkjs/splunk"], function ($, react, mvc, splunk_js_sdk) {
const e = react.createElement;
const useEffect = react.useEffect;
// Get version from conf file
var version;
mvc.createService().get("/servicesNS/-/my_app/properties/config/download", {}, function (err, response) {
if (err) {
console.log("Error:" + err);
return;
} else {
version = response.data.entry[0].content;
console.log("Version from conf: " + version);
}
return version
});
...........Rest of the code (React)..........
});
...which works and displays the version in the console.log Version from conf: old inside function, but my real issue (which I am not able to see it) is that I am not able to figure it how to get out that result into a variable, for example:
var version = old
This looks like an asynchronous function with a promise (not sure) but my knowledge (I must admit) is not so great in this area.
I have found my inspiration from here and I have adjusted a bit for my needs.
In the end I am thanking in advance to anyone who will shed a bit of light for me here.
Thank you, George
maybe this is not the best idea, or solution, but I have exposed the variable into a hidden field value in my page and from there I was able to use it anywhere in my code pages.
Until another idea will pop up, I am satisfied with my solution.
Thanks to anybody that have had a look on this and to anybody who will contribute further on this.