January 3, 200620 yr This may have been asked before, but I'm having trouble coming up with the proper search terms to find it, if it has. Anyway my question is pretty basic: I'd like to generate a list of random dates when the user requests it and enters those dates into the proper table. My set up is like this: I've got a client table. Each client in the table can have multiple dates associated with it. So, the clientID is a foreign key in a one-to-many relationship with dates. I'd like the dates table populated with the foreign key (obviously) and the random dates. Any ideas? I'm running FM 7, if that matters. (Please remember that I'm a newbie. )
January 3, 200620 yr A little more detail would be useful here, such as how many records would you like to generate (defined by user input? or are we talking about populating a field in existing records?) and would you like to set some boundaries for the random dates (FMP7 calendar spans from Jan 1, 0001 to Dec 31, 4000).
January 3, 200620 yr Author Ah, yes. Detail. I need 12 months of random dates, one per month (so a total of 12). The end date is defined by the date of the request. The "date" records need to be created by the script, but the client records will be created prior to generating the dates. Thanks.
January 3, 200620 yr I'm afraid it's still not clear: I understand you want 12 records generated, one for each month, and each has a date that is a random day in that month? But which is the first month? Perhaps if you told us what this is good for, it would be easier to understand the requirement.
January 3, 200620 yr Author Man, sorry I'm having a hard time explaining myself. Thanks for sticking with me. Anyway, the first date is defined by the date the request is made. That is, if I want a set of dates generated today, the start date is today and the end date is 12 months from now. Thinking about it a little more, it may make sense to have the start date user-defined, with the default being the current day (if that makes any sense). The gist of the project is that I need to randomly select one therapy session per month per client over a 12 month period for review. I want FM to generate the random day per month and input it into the table.
January 3, 200620 yr I am still not sure I get this (what happens if the client does not have a session on that day?), but try the attached to get you started. GenerateRandomDates.fp7.zip
January 4, 200620 yr Author comment, Thanks for that! That looks about right. Now I need to figure out how to get it into my file. Looking through it, it seems pretty straightforward. I've got one question though: what is "ScriptParameter"? Is that a special Get() argument? Thanks a ton. I'll let you know if I've got any more questions. :
January 4, 200620 yr Author Sweet. Got it working. I got caught with the "optional script parameter" on the "generate dates" button, but I got it figured out. Thank you very much. :
January 4, 200620 yr Author One more question: how can I automatically compose an email with these newly created dates? What I'm trying (not working right) doesn't get to the point of pasting the data. I can select the right dates and copy them but I can't get them to be pasted into the email window. It looks like I might have to put it in the message field in the dialog box but I don't know how. Thoughts?
January 4, 200620 yr Author Well, I keep answering my own questions. I guess that's a good thing. This is probably a crude hack but it seems to work... I created a global field, pasted the contents of the found records in there and used that field in the "message body" area of the dialog box. The one thing I'm not too happy about is that the global field doesn't "clean itself up" afterwards so I've got to have the script select the contents of the field and clear it out. I thought globals weren't stored?
January 4, 200620 yr Globals are not stored in the file itself. They are user session specific. So when you close out the file, the global field will retain the original value in the main hosting file.
Create an account or sign in to comment