Jump to content

Trying to create a simple WHILE calc


Recommended Posts

Howdy all:

The goal is to take the contents of the Notes field from each record in a found set and combine them into one field with a line space between each note entry; it'll then end up as a text inserted into a Send Mail script step.

Rather than the traditional way of looping through a found set of records to create this--or even using a Summary (List of) field--I thought I'd try my hand at using the (new) WHILE command but for the life of me I can't figure out how it works even after re-reading Skeleton Key's fine article ( https://skeletonkey.com/filemaker-18-the-while-function-looping-in-calculations/ ). I'd appreciate some guidance in putting it together...or if it's not a good way of doing it with WHILE I'd appreciate input on that, too.

 

Thanks tons,

Rich

Link to comment
Share on other sites

11 hours ago, WF7A said:

if it's not a good way of doing it with WHILE I'd appreciate input on that,

It may be a good exercise, but since a script is already running anyway, my preference would be to go the "traditional" way, as you call it.

A summary field defined as List of Notes should give you the required result directly - unless an individual note can contain returns.

Anyway, doing it with While() is fairly simple:

While ( [ 
i = 1 ;
result = ""
] ; 
i ≤ Get ( FoundCount ) ; 
[ 
result = List ( result ; GetNthRecord ( YourTable::Notes ; i ) ) ;
i = i + 1
] ; 
result
)

 

 If you want a double space between the notes then change:

result = List ( result ; GetNthRecord ( YourTable::Notes ; i ) ) ;

to:

result = List ( result ; GetNthRecord ( YourTable::Notes ; i ) & ¶ ) ;

(but this assumes there will be no empty Notes fields).

 

 

Edited by comment
  • Like 1
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...

Important Information

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