Hey there, was attempting to validate the entry of a date selection in a form. I want to present an error if the date entered is over 60 days old. But I’m getting an error of "Cannot convert "date" to a number.".
Wondering if anyone can point out what I’m doing wrong here:
{formdate: MM/DD/YYYY; name=OpenDate}{if: OpenDate > {time: MM/DD/YYYY; shift=60D}}{error: Date is older than 60 days; block=yes}{else}{endif}
I’m guessing it has to do with the slashes in the date. Is there a better way to validate the date is older than 60 days?
You can do that by using the Unix Timestamp X, which gives you the time in seconds.
{formdate: MM/DD/YYYY; name=OpenDate}{if: {={={time: X}/60/60/24}-{time: X; at={=OpenDate}; pattern=MM/DD/YYYY}/60/60/24}>60}{error: Date is older than 60 days; block=yes}{else}{endif}
To explain what I did:
I converted the OpenDate variable to Unix Timestamp
I converted the current date to Unix Timestamp
I divided both numbers by 60 to get minutes then again by 60 to get hours, then by 24 to get days
I subtracted the smaller number from the bigger and checked whether it exceeded 60
Then I continued with the rest of the commands that you created
I am trying to wrap my head around this one so I can find out if todays date falls between 2 weeks after a starting date and 2 months after the same starting date.
Ohhhh! I see where you are going with that! Now, let's say that the starting date is not a form field, but a date in M/D/YYYY format that is pulled into the snippet via regex?
No need. Just make a text field instead of the date picker, give it the same label, and change the pattern setting to the date format you want to recognize.
I’m a little unclear @Cedric_Debono_Blaze. I need the date field to be pulled in via regex because that date is different for every student record and it is what drives the rest of the snippet logic. I could easily use the site selector and name the field but in Salesforce Lightning, site selector is incredibly unreliable because if multiple tabs are open in salesforce, it throws off the selectors. Any thoughts?
Did you see the updated version of the snippet in the post further up? I've changed the date selector to a regular text field that accepts dates in the format you specified. Since Salesforce selectors are a bit tricky, you could just copy the date and use the {clipboard} command as the default for the text field.
That makes perfect sense. Thank you! However, I do not want the user to have to copy/paste data into that field. When they run this snippet, it needs to pull in the date automatically (I imagine via Regex), then use that value to drive date shifters. Here is the direction we have in plain text that I am trying to automate with TB:
Assign Task Per Below:
• 2 weeks-2 months after start date (Campus) / 1 month-2months after start date (Online): Dahly Jimenez
• VA COE (VA FA COE process and first 30 days after start): Lady Marcellus
Otherwise...
• Campus VA Students (A-Z): Armand Izzo
• Online VA Students (A-F): Reggis Metayer
• Online VA Students (G-O): Dahly Jimenez
• Online VA Students (P-Z): Vien Le (Delgado)