Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 6710 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I have a script defined that determines a Text string for years, where the output looks like "2004 2005" or "2006 2007", etc. I want to call this script from a calculation. Is it possible?

The idea is I want to autofill in a field with the text strings above when a new record is created. If the above isn't possible, can someone suggest a way of accomplishing this task?

Posted

autofill in a field with the text strings (2004 2005" or "2006 2007) ... when a new record is created...

Auto-enter of a text string (via calculation based upon specific date criteria when new record is created) is pretty straightforward. But why do you want to put two dates together when we are in the business of splitting data and keeping it split? What do these dates represent to you and where do they come from?

It appears that you are attempting to turn a regular date into a year range for some reason? Can you provide a bit more information for us?

LaRetta

Posted

These would be academic years, which run from June through May. Keeping track of, say, courses, I would want to know if someone enrolled in a class for the 2004 2005 or the 2006 2007 academic year, etc.

Back to the org. question, how would I call a script from a calclation?

Posted

I did in fact read your question. But why do you believe you need a script for it? Isn't all you want to do is set a text field with 2006 2007 etc? Is the field you wish to set in another table? Or do you want to set this field through the entire record-set? Or is this something which will be set (as you describe) upon record creation?

How will you know which years to insert? Do you have a date field, such as EnrollDate?

Posted

I'm thinking it should be a script because I was trying to break the problem down -- this is used is more than one loaction in the database. Is that wrong?

It should be generated upon record creation. The idea is that a button is hit, creating a new record in a different table (for class registrations), and sets the year field to the current academic year (as well as setting a few other values).

The script generates the current academic year, so clicking it today would generate 2006 2007, but clicking the button on June 1, 2007 would generate 2007 2008.

I was thinking this morning, I could just copy the calc from the year script into the calculation field for setting the value of the field, but then that same function becomes decentralized, i.e. located in many places, which I wanted to avoid -- it just seems to go against basic design principles of "write once, reuse always".

Posted

This is a FAQ in every developement tool be it c++ or a database tool like this...

Try to throw "procedure vs function" in Google, and you get your boots filled.

However is the common rule that functions returns something to a field, while procedure but more deal with what's in the fields. Translated to Filemaker are functions handled via Calculation fields and Procedure are here called scripts. But as you can see from your googled stuff is the threshold a little iffy...

However is what you require without doubt functionally dependant to the entry of creation date, so it's merely an aspect of it or a certain styling if you wish ...so it's something "Returned" and in this case is it just for eyeballing, noone cares if it has a value if the record isn't shown. This talks in favour for a unstored calc'field looking like this:

Case ( Month ( aDate ) ≤ 6 ;

GetAsText ( Year ( aDate )-1 ) & " " & GetAsText ( Year ( aDate ) );

GetAsText ( Year ( aDate ) ) & " " & GetAsText ( Year ( aDate)+1 ) )

Where the returntype should be text. Now the use of an & is all it takes to make numbers turn text, but here have I chosen to show all the steps sans typecasts.

--sd

Posted

The idea is that a button is hit, creating a new record in a different table (for class registrations), and sets the year field to the current academic ... so clicking it today would generate 2006 2007, but clicking the button on June 1, 2007 would generate 2007 2008.

You have two issues: 1) Determining the current AcademicYear and retaining the results in a field. You can use Get(CurrentDate) to determine the current Academic Year. But might a person enroll for an upcoming academic year? Example, just because the current date is 5/31/2006, they may actually be enrolling for 2006 2007 academic year? That is why I asked about an enroll (or registration) date.

This is used in more than one location in the database. I could just copy the calc from the year script into the calculation field for setting the value of the field, but then that same function becomes decentralized.

You can't display unless you use a field. So if you want to display the current AcademicYear, use Get(CurrentDate) in an unstored calc. If you want a FIELD to retain that value (upon record creation) then it must be standard field or calc (stored) or must be based upon a date field (such as EnrollDate) instead of Get(CurrentDate). Here is an example of a calc (result is text) which, upon record creation, inserts the current AcademicYear. I see no reason for typecasting:

Let ( [

base = Get ( CurrentDate ) ;

start = Year ( base ) - ( Month ( base ) < 6 )

] ;

start & " " & start + 1

)

LaRetta :wink2:

Posted

Now the use of an & is all it takes to make numbers turn text...

Numbers work in text fields just fine even without the ampersand and will perform math perfectly as well. :wink2:

Posted

I don't follow. Example text calculation of: 3 + 9 & Get ( CurrentDate)

... produces 127/13/2006 without using GetAsNumber or GetAsDate or GetAsText to change typecast. Of course you need ampersand to combine fields and text strings (or to add a space) but ampersand isn't what changes a typecast - it would work without the ampersand.

I was just clarifying for people who might misinterpret your sentence of "...the use of an & is all it takes to make numbers turn text.." because they may think they NEED the ampersand for a simple 3 + 9 if they don't want to add the GetAsNumber.

:wink2:

This topic is 6710 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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