Continued thanks, @sylumer, for trying this out many times.
I’ve now produced a (nearly minimum) non-working example, along the lines of StackOverflow. It first tries to add a 2Do project, and then add 4 tasks to that project. Full code is:
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// always-run-in-app: true; icon-color: yellow;
// icon-glyph: magic;
// term-plan-parse
// JS Core for Scriptable app
//
var projectTitle="5-May Test Talk project"
var notes="Series: something"
var startStr1="29/04/2019"
var startStr2 = "01/05/2019"
var dueStr = "04/05/2019"
var pid = addProject(projectTitle, notes, startStr1, dueStr, "Talks")
addTask("Decide talk point","", startStr1, dueStr,projectTitle,pid)
addTask("Write talk","", startStr1, dueStr,projectTitle,pid)
addTask("Prep slides & props","",startStr2, dueStr,projectTitle,pid)
addTask("Practice & print","",startStr2, dueStr,projectTitle,pid)
function dateToYYYYMMDD(dateIn, dayOffset) {
let dt = new Date(Date.parse(dateIn) + dayOffset*60*60*24*1000) // arithmetic in milliseconds
let output = dt.toLocaleDateString("en-GB", {year:'numeric', month:'2-digit', day:'2-digit'})
return output
}
function addProject(title, notes, startDate, dueDate, listName) {
var baseURL = "twodo://x-callback-url/add"
var cb = new CallbackURL(baseURL)
cb.addParameter("task", title)
cb.addParameter("type", "1")
cb.addParameter("forList", listName)
cb.addParameter("note", notes)
cb.addParameter("priority", "2")
cb.addParameter("due", dueDate)
cb.addParameter("start", startDate)
cb.addParameter("ignoreDefaults", "1")
console.log("- addProject for " + cb.getURL())
var result = await cb.open()
var projectID = result.add
console.log(" - callback returns " + projectID)
if (projectID != "") {
return projectID
} else {
console.error("Problem creating project" + projectTitle)
return ""
}
}
function addTask(title, notes, startDate, dueDate, projectTitle, projectID) {
let baseURL = "twodo://x-callback-url/add"
let cb = new CallbackURL(baseURL)
cb.addParameter("task", title)
cb.addParameter("type", "0")
cb.addParameter("forList", projectTitle)
cb.addParameter("forParentName", projectTitle)
cb.addParameter("forParentUID", projectID)
cb.addParameter("note", notes)
cb.addParameter("priority", "2")
cb.addParameter("due", dueDate)
cb.addParameter("start", startDate)
cb.addParameter("ignoreDefaults", "1")
console.log("- addTask for " + cb.getURL())
let result = await cb.open()
console.log(" - callback returns " + result.add)
if (result.add != "") {
return result.add
} else {
console.error("Problem creating task" + title)
}
return 0
}
(I don’t know how to make this have JS formatting like you manage, sorry.)
This always returns the same error as I quoted before on the first URL call: Error on line 35: Unexpected identifier ‘cb’. Expected ';' after variable declaration.
Please could you or others try and see if this is some error in my setup? I have re-started the Scriptable app a number of times, which doesn’t cure it.