kenneth2k1 Posted January 29, 2002 Posted January 29, 2002 Hey guys! I had a script step that I want to set a field to the date a year from now. I made it look like this: If [ PatternCount("Certain Field", "12 Month Contact")] Set Field [status(CurrentDate) + 360] Else Set Field ["Certain Field", "select"] It won't work. The date that shows up is only one month from now, not 1 year. I have similar steps for finding dates that are 2,3,4,5 and 6 months from now, and they all work fine. Its just the year one that won't work. Any Ideas? Thanks, Ken
kenneth2k1 Posted January 29, 2002 Author Posted January 29, 2002 Correction: The month it shows is 2 months away, instead of being a year away. Thanks all!
Vaughan Posted January 29, 2002 Posted January 29, 2002 The Set Field should be using this calculation: Date(Month(datefield)+2, Day(datefield), Year(datefield))
kenneth2k1 Posted January 29, 2002 Author Posted January 29, 2002 Thanks for the reply. I tried that: it actually gives me the same results. The script is suppose to spit out a date so that FM can analyze it in the future. The date it gives is based on which value list item is selected. There is "2 Month Contact," "4 Month Contact" etc. The only one it will not work for is the one where "12 Month Contact" is selected. This script is not for the user's benefit, because most everyone can figure out what the date will be in about a year from now. The problem I am having is when "12 Month Contact" is selected today, I get "March 28, 2002," not "Jan 28, 2003." Help, please? Ken
Steven H. Blackwell Posted January 29, 2002 Posted January 29, 2002 Given a field of type date called "date_field" the following script step will increment that by 365 days: InsertCalculatedResult [status(CurrentDate)+365] HTH Old Advance Man
Vaughan Posted January 29, 2002 Posted January 29, 2002 Don't use a script, use a calculated field: code: Case [ PatternCount("Certain Field", "2 Month Contact"), Date(Month(datefield)+2, Day(datefield), Year(datefield)), PatternCount("Certain Field", "12 Month Contact"), Date(Month(datefield), Day(datefield), Year(datefield)+1), "default entry"] This will update itself whenever the Certain Field is changed automatically. BTW using a calculation like "date + 365" to add a year or "date + 30" to add a month is not good because it has error built into: years aren't 365 days and months aren't 30. Use the Date() function.
Garry Claridge Posted January 29, 2002 Posted January 29, 2002 Here is my reply to a similar question you asked four days ago: Assume you have a field called "last_app" which is the date from which the next appointment is made. You have a field "next_app_period" which has the value list result. Create a calculation field called "next_app_period_num" which converts the text to a number of months: Case(next_app_period = "2 Month",2, next_app_period = "3 Month", 3, next_app_period = "4 Month",4,next_app_period = "5 Month",5,next_app_period = "6 Month",6,next_app_period = "9 Month",9,next_app_period = "12 Month",12,0) Now create a calculation field "Projected Contact Date": Date(Month(last_app)+next_app_period_num,Day(last_app),Year(last_app)) This will give you the date for the next appointment. It works! Hope this helps. Garry ------------------------------------------------------------------------
Vaughan Posted January 29, 2002 Posted January 29, 2002 He He... you almost had me with the Today function: blood was rushing to my head and I was reaching for the keyboard! For those that don't know, Today is an old function that's only still in FMP for backwards compatibility. On the surface "Today" looks great until you read the fine print: it only calculates when the database is opened. If you leave it running continuously for more than one day it'll be wrong. FM Inc invented the Status(CurrentDate) function to replace it. It's 8:30 am here so I've got the rest of the day to chuckle about the Today function. Thanks.
kenneth2k1 Posted January 30, 2002 Author Posted January 30, 2002 Thanks, guys for all of your help. Garry, thanks for your input. Yes, at first I used your calculation, but then I wanted some other things to happen, so I made a fast script to take care of those other things. I soon realized that I didn't really need those other things to happen, so I went back and just used Vaughan's calculation. Vaughan, thanks for the info. I will avoid doing formulas like that. I was thinking about using the "Today Function." What do you think? (hahah, just kidding) By the way, is there any limit to the amount of steps that can be put into a script? Thanks for your help! Ken
Recommended Posts
This topic is 8337 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now