Things Due Date Issue

I’ve got a Script I’ve written to send a task to Things with a prompt for what project and due date. For some reason, even when I have it configured (at least I think I have it configured) to send only a date, and not a time, Things still shows a reminder on the date selected, but at the time the action was run.

Here’s my code:

// Things Prompt for Project


// Create Prompt to ask user for project and select whether or not to add a heading
var p = Prompt.create();
p.title = "Project";
p.message = "Enter a Project Name";

// Create fields in prompt for project and heading
p.addTextField("project", "Project Name", "");
p.addTextField("heading", "Heading Name", "");
p.addSwitch("due", "Select Due Date?", true);
p.addButton("Done");

p.show();

var project = p.fieldValues["project"];
var heading =     p.fieldValues["heading"];

if (p.fieldValues["due"] == true) {
  var q = Prompt.create();
  q.title = "Select Date";
  q.message = "When would you like to complete this task?";
  q.addDatePicker("date", "Date", new Date(), {"mode": "date"
  });
  q.addButton("Done");
  q.show();
  var when = q.fieldValues["date"];
}
else {
var when = ""
}

// Add task to todo with user input as project and heading.
var todo = TJSTodo.create();
todo.title = draft.content; // Use draft content for task title
todo.list = project;
todo.heading = heading;
todo.when = when;

var container = TJSContainer.create([todo]);
var cb = CallbackURL.create();
cb.baseURL = container.url;
var success = cb.open();
if (success) {
console.log("Task added to Things");
}
else {
  context.fail();
}

If the spacing is weird, some things may have shifted in my pasting as code here.

Anyway, any help is appreciated.

I haven’t spent too much time with the ins and outs of the Things URLs, but the when property wants a string value, see their docs.

If you set it to a JS data object, it’s going to get coerced to a string by JS, and that string will include a time.

Some of the other Things scripts in the directory might have some boilerplate for outputting the date string Things is looking for (YYYY-MM-DD).

1 Like

Blah. I’ve even written scripts that have converted date objects to strings. Can’t believe I forgot that. Script fixed. Thanks Greg.

2 Likes