Thanks both of you! @fortred2 In case this comes up again, can you explain the difference in functionality between your code and mine? (Or are they supposed to be the same)
@CalderH I searched for posts in this community forum that contain the text get_menu_item_value and found a post from Andreas. There, you'll see Andreas uses...
await callBTT("get_menu_item_value", {
... instead of this, as you do in your script...
await get_menu_item_value(
Your version of the script should work soon.
Unfortunately there's no mention of callBTT in the docs.
callBTT was used in the past and is still used internally, but users can now directly use the shorter java script calls - the result should be the same. A version with the fix will be available in a few hours!
Hi — continuing this thread because it may be a related issue, but let me know if it would be better to make a new thread. I now have this code for the submit button, to get the values of multiple inputs:
async function recordAnswers() {
let itemNames = ['q1', 'q2', 'q3'];
answers = {};
for (let itemName of itemNames) {
// Get the value of each input and add them to answers
let itemVal = await callBTT(
'get_menu_item_value', {
menu_name: 'Focus',
item_name: itemName
}
);
answers[itemName] = itemVal;
// Clear each input field
await callBTT(
'set_menu_item_value', {
menu_name: 'Focus',
item_name: itemName,
value: ''
}
);
};
let answerString = JSON.stringify(answers);
return answerString;
};
(Still using callBTT since I didn’t see the new version when I checked for updates — is there somewhere else I should look?)
This code is behaving erratically — sometimes it does work as expected: it returns a stringified object where the keys are the names of the fields and the values are my inputs, and it clears the input fields. However, usually what happens is it returns an object where the values are all empty strings — {q1: '', q2: '', q3: ''}, and the inputs aren’t cleared. If I change the call to set_menu_item_value so that it replaces the value with something other than an empty string, then that string appears instead in the output (like {q1: 'a', q2: 'a', q3: 'a'}, while the text in the menu itself does not change.
Am I doing something wrong? I worry I am still new to JS and misunderstanding how to use asynchronous functions.