I am trying to enter a surgery date and the calculate the 90 day global period into another field.
I am struggling with the add dates function and using the document variables in how to write this, any help appreciated.
Here is what I have now. I would like to take the date in the DOCUMENT.SURGERY_DATE field and add 90 days to it and store the result in the DOCUMENT.GLOBAL_PERIO field.
{ADDDATES(str("DOCUMENT.SURGERY_DATE"))"0","0","90")
DOCUMENT.GLOBAL_PERIO
thanks in advance!!
Try this:
In the Mel section of your Display Field:
{fnGlobalPerio()}
====================================================================
In the code window of the form:
fn fnGlobalPerio()
{
local sDocDate=sub(str(DOCUMENT.SURGERY_DATE),1,10)
local sGPDate=ADDDATES(sDocDate,"0","0","90")
DOCUMENT.GLOBAL_PERIO=sGPDate
return sGPDate
}
Thank you that worked great.
If you have a few minutes can you explain what happened here. This code is more than I have ever done before and I am not quite sure how it all works. If you do not, no worries.
thanks!
Firstly, I find it easier if you are trying to accomplish multiple things to a) put it into a function instead of trying to cram it all into the Mel section of a field and b) break it down into smaller steps with the use of Local variables. This helps to avoid typos such as adding an extra parentheses, which is one of the problems you had in you original code.
Secondly, I forget the reason why I started "sub"stringing my dates prior to using them in AddDates, but I am pretty sure I was getting either errors or funky results either due to extra spaces at the end or possibly a time section reflecting 12:00:00 am at the end.
You could even skip the line "DOCUMENT.GLOBAL_PERIO=sGPDate" if you are actually not using this document variable anywhere else in your form. I just included it because I thought you still might need to set the value to your calculated date if you were still using it elsewhere.
Thank you!!