Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

  • Author

Correction: The month it shows is 2 months away, instead of being a year away.

Thanks all!

The Set Field should be using this calculation:

Date(Month(datefield)+2, Day(datefield), Year(datefield))

  • Author

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

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

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.

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

------------------------------------------------------------------------

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.

  • Author

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

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.