Assigning StartDate attribute

I’m puzzling through a stamp that creates a Note for a particular week, and sets the $StartDate of that Note to the first day of that week.

I can’t seem to assign $StartDate.

// Action code to create a Note in yyyy-Week-ww format
//
// Set this variable FIRST!
var:number vWeek=39;
//
var:number vMyNum;
var:date vdayOne;
var:string vProto="pWeek";
var:string vNote;
var:string vPath="/CY2023";
var:string vNewNote;
// Calculate day of week start = vWeek*7-6
vMyNum=(vWeek*7)-6;
vdayOne=("2023-01-01");
vNote="2023-Week-"+vWeek;
//
vNewNote=vPath+"/"+vNote;
// Make a note for the week
create(vNewNote);
// Set some attributes
$Prototype(vNewNote)=vProto;
$Week(vNewNote)=vWeek;
$StartDate(vNewNote)=date(vdayOne+(vMyNum+" days")).format("y-M0-D H:mm");
// Fill the $Text with some debug info
$Text(vNewNote)+=vNote+"\n\n"+vdayOne+"\n"+vMyNum+"\n"+$StartDate;

Is there a format that StartDate should use?

No. These lines are wrong:

$StartDate(vNewNote)=date(vdayOne+(vMyNum+" days")).format("y-M0-D H:mm");
// Fill the $Text with some debug info
$Text(vNewNote)+=vNote+"\n\n"+vdayOne+"\n"+vMyNum+"\n"+$StartDate;

and should be:

$StartDate(vNewNote)=date(vdayOne+(vMyNum+" days"));
// Fill the $Text with some debug info
$Text(vNewNote)+=vNote+"\n\n"+vdayOne+"\n"+vMyNum+"\n"+$StartDate(vNewNote).format("y-M0-D H:mm");

You only format a date in the above fashion if you want a string representation of the date, e.g. to use in $Text as in the last line. When setting (changing) a Date’s value format should not be used.

Also, in the last line $StartDate will likely have a value of never so the correct code is more likely $StartDate(vNewNote) as set two lines above. But as we’ve only part of the code it’s hard to tell the wider context.

2 Likes