01-15-2023 10:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-15-2023 10:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello,
I am really stuggling with how to allow someone to change a simple date format via the settings.
I copied the info verbatim a number of times from the SDK and the console logs always return undefined, null or [object OBJECT] with the exception of evt.oldValue and evt.Newvalue which log out as:
settingsStorage.addEventListener("change", (evt) => {
// Which setting changed
const dateArr = JSON.parse(evt.newValue);
console.log(dateArr);
const myArr = (dateArr.values);
console.log(myArr);
console.log(myArr.name);
console.log(`val: ${evt.data}`);
01-15-2023 11:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-15-2023 11:31
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You're exceptionally close!
Can I just leave a clue? values (and selected) and both arrays; that's why you see Object and undefined sometimes. Experiment with things like values[0]. You may still need to dig a bit deeper depending on what you want.
Gondwana Software

01-15-2023 13:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-15-2023 13:10
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
oh I tried that but values[0] or values[1] just always return null. I went back and worked on selected to see if I would have more luck. Good news and bad news. Good news is I can get at the array position of the date format. Bad news in the messaging listener in the app index.js file always returns undefined or [object OBJECT] no matter what I do. evt.data | evt.data.value (as shown in the sdk) return and empty array of objects and evt.newValue returns undefined. Now I had that error before and when I used JSON.parse() it helped out but in this case it returns a JSON string parse error in the app index.js.
So I think it is still a step forward but it was into a hidden pile of quicksand

01-15-2023 13:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-15-2023 13:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I suspect you're not sending a string from companion to device. Check that.
Gondwana Software

01-15-2023 14:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-15-2023 14:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Ok...first...thank you @Gondwana for trying to help and guiding me. I sincerely appreciate it. As much I would have loved a definitive answer, it is always rewarding to find a solution rather than be given one directly.
Second. I copied directly what was out of the SDK. One would think that whomever wrote the examples in the SDK would have tested them out. One would likely be wrong more often than not I am finding.
Third: This is more stream of consciousness as a record of what I did to get it working in case someone else struggles with this. I get it may not be pretty. I get it may not be elegant but if all you need is to get from A to B a 1982 Chevette works just as well as a Ferrari.
- I did try to send the string by commenting out the //key: key; line in the sendValue function but that got me the same old undefined errors.
- I then rewrote all the functions to just send the evt.newValue but same result. I did verify via a console.log that I am sending just the array of objects but something was still off.
- I then rewrote the entire sendValue function in the companion.
- function sendValue(val) {
if (val) {
const dateArr = JSON.parse(val);
const valObj = dateArr.values;
const selectObj = dateArr.selected;
const objDate = selectObj[0];
sendSettingData(objDate);
console.log(objDate);
} - Then reworked my switch case
messaging.peerSocket.addEventListener("message", (evt) => {
const dateFormat = evt.data;
switch (dateFormat) {
default: {
lblDate.text = `${day}/${month}/${year}`;
}
case 0: {
lblDate.text = `${month}/${day}/${year}`;
break;
}
case 1: {
lblDate.text = `${day}/${month}/${year}`;
break;
}}

01-15-2023 18:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-15-2023 18:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Glad you got it going.
One common gotcha with Javascript is its loose typing. For example, it often tries to convert things to strings automatically, which is why a non-string variable may look like a string when you use console.log(). A safer way to determine a variable's type is to use typeof.
Gondwana Software
