Copy link to clipboard
Copied
The script below is located in the custom calc of AutoForHire dateObject field. The goal is to examine the value from NewBusinessName text field and ultimately assign it to a date using the script below. I have flipped this around every which way I could think of, but it just won't work. In the different scenarios I have tried, error messages included recognizing variable setDate statements as functions, which I have been stuck trying to correct. My latest attempt uses if/else conditions but assigns variables to the date modifications, and I've tried combining setDate and setMonth with and without as variables to clean it up also, but nothing works. Any help greatly appreciated! File attached.
var firstLetter = this.getField("NewbusinessName").value;
currAFHDate = new Date();
var stAFHREGA = util.scand("mm/dd/yyyy", currAFHDate);
var stAFHREGA = currAFHDate.setMonth(05);
var stAFHREGA = currAFHDate.setDate(01);
var stAFHREGBC = util.scand("mm/dd/yyyy", currAFHDate);
var stAFHREGBC = currAFHDate.setMonth(06);
var stAFHREGBC = currAFHDate.setDate(01);
var stAFHREGDE = util.scand("mm/dd/yyyy", currAFHDate);
var stAFHREGDE = currAFHDate.setMonth(07);
var stAFHREGDE = currAFHDate.setDate(01);
if(firstLetter === "") {event.value = "";}
else if (firstLetter === "a"||"A") {event.value = util.printd("mm/dd/yyyy", stAFHREGA);}
else if (firstLetter === "b"||"B"||"c"||"C") {event.value = util.printd("mm/dd/yyyy", stAFHREGBC);}
else if (firstLetter === "d"||"D"||"e"||"E") {event.value = util.printd("mm/dd/yyyy", stAFHREGDE);}
found this mistake and thought I solved it- not!
var currAFHDate = new Date();
yes, that did it Bernd! Thank you!! I haven't seen it done that way before- thanks for the education!!!
Copy link to clipboard
Copied
You can't use the functions setMonth and setDate on text strings. You must use date objects.
Copy link to clipboard
Copied
I thought the util.scand converted it into a date object acceptable value, and then this is folllowed by the util.printd to display the field's value. Where am I going wrong?
var firstLetter = this.getField("NewbusinessName").value;
currAFHDate = new Date();
var stAFHREGA = util.scand("mm/dd/yyyy", currAFHDate);
stAFHREGA = currAFHDate.setMonth(05);
stAFHREGA = currAFHDate.setDate(01);
event.value = util.printd("mm/dd/yyyy", stAFHREGDE);
Copy link to clipboard
Copied
my latest attempt. Cannot get past this function error. Do I have to declare a variable for the individual date and month when setting them? Do I need to insert a util.scand following the setDate script? Nothing I seem to try works- I know I must be missing something simple but I just can't see it? Extra eyes please!!!!
var firstLetter = this.getField("NewbusinessName").value;
currAFHDate = new Date();
var startAFHDate = util.scand("mm/dd/yyyy", currAFHDate);
if (firstLetter == "") event.value = "";
else if (firstLetter.toLowerCase() == "a") startAFHDate.setMonth(05).setDate(01);
else if ((firstLetter.toLowerCase() == "b")||(firstLetter.toLowerCase() == "c")) startAFHDate.setMonth(06).setDate(01);
else if ((firstLetter.toLowerCase() == "d")||(firstLetter.toLowerCase() == "e")) startAFHDate.setMonth(07).setDate(01);
event.value =util.printd("mm/dd/yyyy", startAFHDate);
Copy link to clipboard
Copied
You can set month and day like this:
startAFHDate.setMonth(5,1);
or
startAFHDate.setMonth(5);
startAFHDate.setDate(1);
Copy link to clipboard
Copied
found this mistake and thought I solved it- not!
var currAFHDate = new Date();
yes, that did it Bernd! Thank you!! I haven't seen it done that way before- thanks for the education!!!
Copy link to clipboard
Copied
You can make your code more legible if you moved to the toLowerCase command to the first line, and then you could remove it from all the next lines...
Copy link to clipboard
Copied
This is not valid syntax:
else if (firstLetter === "a"||"A")
It needs to be:
else if (firstLetter == "a" || firstLetter == "A")
Although, an easier way to do it would be:
else if (firstLetter.toLowerCase() == "a")
Copy link to clipboard
Copied
yes, that's much more efficient. Thank you try67!