Okay, I hope I’ve got the gist of what you were attempting to do. I’ve corrected a few errors, reworked the code a little in a couple of places, and added in several more alerts in the hope it will guide you in what it is now doing.
// Goals testing
// Get the JSON file
let fmCloud = FileManager.createCloud();
let file = fmCloud.readString("/Goals/goals.json");
let json = JSON.parse(file);
// // Prompt
/* --------------------- */
let today = Date.today().toString("dddd, MMM d");
let dStamp = Date.today().toString("yyyy-MM-dd");
let p = Prompt.create();
p.title = "Goals Today";
for (let goal in json)
{
let goalName = goal;
let priority = json[goal].priority.name;
let toggle = goal + "toggle";
let field = goal + "field";
let label = goal + ":\nEnough today?";
p.addSwitch(toggle, label, false);
p.addTextView(field, priority, "", {height: "4"});
}
p.addButton("ok");
if (p.show())
{
for (let goal in json)
{
let toggle = goal + "toggle";
let field = goal + "field";
alert("INFO PART ONE:\n\ngoal = " + goal + "\n" + "toggle = " + toggle + "\n" + "field = " + field );
alert("INFO PART TWO:\n\nfield value [" + field + "] = " + p.fieldValues[field] + "\nfield value [" + toggle + "] = " + p.fieldValues[toggle]);
alert("JSON{Current goal}:\n\n" + JSON.stringify(json[goal]));
alert("JSON{Current goal}.priority:\n\n" + JSON.stringify(json[goal].priority));
alert("JSON{Current goal}.priority.enough:\n\n" + JSON.stringify(json[goal].priority.enough));
json[goal].priority.enough.unshift({"date":dStamp,"description":p.fieldValues[field],"enough?":p.fieldValues[toggle]});
let output = JSON.stringify(json);
alert("JSON{Current goal}:\n\n" + output);
let success = fmCloud.writeString("/Goals/goals3.json", output);
}
}
else
{
context.cancel();
}
Let me know if that gets you any closer to what you are trying to do.