AppleScript date problem (MBS?)

I’m using a dynamic AppleScript to create notes in Evernote. The released version works fine. The upcoming version of my app has a hissy fit without changing the AppleScript. The error is “The variable theDate is not defined”. The part of the script that does define the variable is

set theDate to current date

How can this not work? It works fine if I execute the script in Script Editor. But when doing this with the MBS plugin in my main project I get the error. An example also doesn’t show the problem. Changing the current date to

set theDate to date ("31/12/1999")

also works fine. I have a date that I want the note in Evernote to have. Setting this in my app also doesn’t work with the 1999 date.

Here is the complete script with test data:

[code]property theTitle : “2017-06-25 SendGrid - Statistics - 06/18/2017 - 06/25/2017”
property theContent : “test”
property theNotebook : “test”
property theUrl : “1498399065.594fc15967ada@swift.generated”
property DateString : “2017,6,25,15,57,47”
property theTags : “@read

with timeout of 10000 seconds
set theDate to my makedate(DateString)
set TagList to my split(theTags, “/delimiter/”)
tell application id “com.evernote.evernote”
set theNote to create note with html theContent title theTitle notebook theNotebook tags TagList
set creation date of theNote to my makedate(DateString)
set source URL of theNote to theUrl
return 1
end tell
end timeout
on split(theText, theDelimiter)
if theDelimiter is not “” then
set OldDelimiters to text item delimiters
set text item delimiters to theDelimiter as list
set theList to every text item of theText
set text item delimiters to OldDelimiters
set theList to every text item of theText
end if
return theList
end split
on makedate(DateString)
set datelist to my split(DateString, “,”)
set theDate to current date
if (count of datelist) > 0 then
set year of theDate to item 1 of datelist
set month of theDate to item 2 of datelist
set day of theDate to item 3 of datelist
set hours of theDate to item 4 of datelist
set minutes of theDate to item 5 of datelist
set seconds of theDate to item 6 of datelist
end if
return theDate
end makedate[/code]

Xojo 2018r3, macOS 10.13, MBS 19.0.

Any ideas?

@Beatrix Willius — In on makedate, can’t you replace

set theDate to current date

set theDate to data( "01/01/2000" )

and then set the year, month…?

@Stephane Mons: Setting year, month etc happens in the makedate function. I tried the date with the slashes which gave me the correct date. But Evernote didn’t like the result. I ended up using the abbreviated date form from Xojo which ended up as the same date in AppleScript. But the date then made a correct date in Evernote.

Is that within a tell application block?
Maybe you miss that?

@Christian Schmitz: the script works from within the Script Editor. It does not work from my Xojo app. You don’t need a tell block when you aren’t talking to an app.