Can't set task's starting date and ending date

Hi.

I’m trying to write a script that will update the starting date and ending date for a specific task. The script I’m running is as follows.

set myIssue to "ISSUE-1234" -- The issue I'll lookup based on my custom attribute "Issue key"
set newStart to date "7/19/16"
set newEnd to date "7/28/16"

tell application "OmniPlan"
	tell front document
		set t to lookup value myIssue in "Issue key"
		if exists t then
			log "soon to be new starting date: " & newStart
			log "soon to be new ending date: " & newEnd

			log "starting date (before): " & starting date of t
			set starting date of t to newStart
			log "starting date (after): " & starting date of t

			log "ending date (before): " & ending date of t
			set ending date of t to newEnd
			log "ending date (after): " & ending date of t

		end if
	end tell
end tell

When I run this I get the following output.

soon to be new starting date: Tuesday, July 19, 2016 at 12:00:00 AM
soon to be new ending date: Thursday, July 28, 2016 at 12:00:00 AM
starting date (before): Thursday, August 11, 2016 at 2:50:00 PM
starting date (after): Thursday, August 11, 2016 at 2:50:00 PM
ending date (before): Monday, August 15, 2016 at 2:00:00 PM
/path/to/my.scpt:...: execution error: OmniPlan got an error: The end date must come after the start date. (1)

Note that neither starting date or ending date get updated. The error relates to changing the ending date, and even if I comment that out the starting date update still doesn’t take.

Am I missing something obvious?

Thanks.
Justin

Please note that, as you do state, the end date error is not the only indication of a problem, as you do bypass when you attempt to comment out the start date setting.

First try to fix your starting date not being set. Applescript has two ways of value setting, and ‘set’ is not often the best compared to ‘copy’ — each is different beyond merely that a copy ‘copies’ and a set changes the variable address to be that of its second operand (unless it finds that it cannot do that and must copy). For set, you may run into issues if you don’t parenthesize the first operand (seems to occur here?) and set does create variables (apparently not an issue here). Copy does not ‘always’ create variables (which is weird by itself, but not of impact here). Bottom line, the issue may be that the start date setting may need to have parenthesis in the first operand, but I would make it more clear to use:
copy newStart to ( starting date of t )

Without that fix, your end date is still wrong but you may have not gotten to the ‘next’ issue, which is that the end date error is possibly showing up before the setting operation will fail in the same way that the start date setting has failed. Try to convert that to:
copy newEnd to (ending date of t)

Of course, I have not tested this, but I have run into these copy/set and parenthesis issues so often on an applescript project that I have some confidence that something might change. They cause great frustration even though there should be no difference logically.

Dennis