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

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

Recommended Posts

Posted

I have what I thought was a fairly simple script - but I can't get the Loop to work properly.

I have a db of competitors. There is a portal which shows what classes the comp. has entered. I have a field that will be printed which will indicate what classes each comp has entered. The end result I am looking for is a list:

Comp Name, Horse Name, Class number, Class number, Class number, Class number

This script works but is cumbersome as you have to keep changing the row number & clicking yes, then clicking no when you get to the end.

Go to portal row (first)

copy (select, Classes:Class#)

go to field (classes for program)

paste (classes for program)

go to field (classes for program)

insert text ("classes for program" ",")

Loop

go to portal row (by number..)

copy (select, Classes:Class#)

go to field (classes for program)

paste (classes for program)

go to field (classes for program)

insert text ("classes for program" ",")

End Loop

go to record/request/page (next)

but, I would much rather the loop just ran & ended after the last portal row.

I'd also like to not add the "," after the last class number.

I'm sure it's a simple thing about loops that I just haven't gotten into my thick skull.

TIA!

Martie

Posted

Hi:

I admit that I did not read all the intricacies of your script, but I can tell you how a loop structure goes.

In a loop, all actions between Loop and End Loop will be performed in the loop. In order to have it loop from one record to the next, you need go to record steps. So it would look like this:

Go to Record/Request/Page [First]

Loop

perform actions you want

Go to Record/Request/Page [Next, exit after last]

End Loop

Before the End Loop, you can also use Exit Loop If [ ] to check for some value that might terminate the loop.

Sorry this is brief.

Ken

Posted

In order to simplify the scripting and make it easier to do single loop steps, I always put the body of a loop into its own script. NOTE: I added some stuff, its in ALL CAPS.

Script: Main Script

Go to portal row (first)

copy (select, Classes:Class#)

go to field (classes for program)

paste (classes for program)

go to field (classes for program)

insert text ("classes for program" ",")

SET FIELD [GPORTALROW, 1]

GOTO PORTAL ROW [LAST]

SET FIELD [GLASTPORTALROW, STATUS ( CURRENTPORTALROW)]

Loop

PERFORM SCRIPT [bODY OF LOOP]

EXIT LOOP IF [GPORTALROW = GLASTPORTALROW]

End Loop

go to record/request/page (next)

Script: Body of Loop

go to portal row (by number..) <-- USE GPORTALROW

copy (select, Classes:Class#)

go to field (classes for program)

insert text ("classes for program" ",") <-- Notice I removed the redundant goto field and switched

paste (classes for program) <-- positions of the "," so that it does not get stuck on the end.

SET FIELD [GPORTALROW, GPORTALROW + 1]

You actually need to do one additional thing and that is to test at the "Insert Text" to see if anything is in the field. If there is something in the field, then add the ",", otherwise insert "".

Posted

ah ha! Thank you so much!

couple of things -

set field GPORTALROW - needs to be set at 2, otherwise you get the first class # listed twice

I added an if at the end of the loop - that said if GPORTALROW < GLASTPORTALROW then put in the "," - I kept the original order of pasting the class number & then adding the "," because otherwise you get an extra "," at the beginning of the list of classes.

I MAY be BEGINNING to understand these Loops - seems like I always want to leave out a step or two - which causes many headaches. Also am BEGINNING to understand the many cool uses of global fields.

one last question - in working on the script I had to delete the other portals on the layout & then put them back after I got the script working properly. This, even tho' I tried to make the portal I was working with be in "front" - is there a way I don't know about to make a particular portal the active or in front one so that a go to portal row script step will work with it? I tried making it in front by Arranging it to go to the front but that didn't seem to do anything (fmp 6.0v4) Also - is there a way to set scripts for more than one portal on the same layout? dont' have a need for this at the moment, but one of these days....

Thank you again!

Martie

Posted

To go to a specific portal, you need to go to a field in the portal, as a 1st step (otherwise FileMaker goes to the Back portal, which is first layout-wise). Then go to a particular row, i.e.:

Go To Field ["Classes:Class#"]

Go to portal row (first)

Copy (select, Classes:Class#)

go to field (classes for program) <-- this step is unnecessary

paste (classes for program)

go to field (classes for program) <-- this one too

insert text ("classes for program" ",")

Copy [select], Paste [select] and Insert [select] have the target in the step already, that's what "select" is, no need to go to field first.

You only need Go To Field ["Classes:Class#"] to solve the multiple portal problem, and also to "lock" the record, if there are multi-users.

I hate to say it, but what you are doing may not be necessary, and is kind of redundant. If you printed from the Classes file (which is really a Competitors_Classes file), with a Subsummary part sorted by the Competitor (or CompetitorID), then you could get your list:

Competitor

Class#

Class#

Class#

Alternatively, there's a fancy-dancy way to use ValueListItems in a calculation to produce what you want,

Comp Name, Horse Name, Class number, Class number, Class number, Class number

in either file, ie., class#'s as a unstored text block. No scripts needed. I could make an example file if you want.

Question: you have Competitor and Horse

Is there only 1 horse per competitor? If not, what is the relationship to Classes?

Posted

I agree that this is a roundabout way of getting what I want - however, I am dealing with a couple of givens that I didn't elaborate upon.

The list that I am generating needs to be exported - ending up as an Excel file so that it can be emailed to the show manager who will incorporate it into the printed show program. She doesn't use or have fmp since she doesn't need to deal with the data management of each show. I work as a long-distance secretary to many different horse shows (I live in FL, but work for shows not only in FL but also NC, MN, MD, OH, etc.) It is more efficient to have the show manager create the show program so that we don't have to bother with mailing or having me tote 300+ show programs in my luggage (I am on-site during the show itself).

The relationship is based on the bridle number of the horse/rider combination. Compeitors may ride more than one horse, each horse may have more than one rider, but each horse/rider combination has it's own unique bridle number.

I think I see where I was mistaken in the use of multiple portals & the go to portal row function, however, given your explaination above. I had thought that the defination of the go to portal row function was to use the portal that was "in front" on the layout - I see from your explaination that I had it backwards. Thank you.

Posted

This is how I'd do the comma-delimited list of classes.

It uses an Unstored calculation, based on a value list, which is filtered by the relationship.

It also Substitutes commas for returns in the result, to format as a single line.

It sounds complicated, but it requires no script, hence no button.

Competitor_Classes.zip

  • 2 weeks later...
Posted

I have the opposite problem to solve.

I have a field ("response_set") that contains comma delimited numbers. I need them to populate a portal ("::responseNumber") - each number to go into a new row on the portal. (portal has no data at start)

I substituted the commas for spaces so that I could use the Left word, middle word, etc., going from portal row to portal row, but the "response_set" field is different for every record.

I think the logic is:

look at "response_set",

copy (cut?) first word,

paste into first row on portal;

copy next word,

paste in next row on portal,

loop until no more words in "response_set"

but how do I say this in Filemaker-speak?

Thanks!

Posted

[i can't tell if I already sent this. I though I did, but I don't see it. So here it is, again?]

Here is one way to do what you want (see file). I tend not to use Copy/Paste. Unless you really must transfer styled text, it's not needed; it's slower and more prone to error than internal strictly FileMaker routines.

This uses a relationship with "allow creation of related records." It can be on a hidden layout, but you must go there in the script, because of the "Go to Field" step.

Freeze Window

Set Field [

CreateRelated.zip

Posted

In the words of Jim McKee

...Fenton ...

Freakin' elegant! Nice job

Thank you! I had to add "pause scripts" throughout to see what all the steps were doing, but as soon as I saw what was happening, I was able to tweak it for my situation. It's great learning all the different ways that globals are used in scripts.

I can't wait till someone posts a question that I can help with!

Thank you AGAIN!

Posted

CamMac2 said:

I have the opposite problem to solve.

I have a field ("response_set") that contains comma delimited numbers. I need them to populate a portal ("::responseNumber") - each number to go into a new row on the portal. (portal has no data at start)

If the portal is set to allow creation of related records, and you're on a Mac, it's reeely easy.

copy cell "ResponseSet" of current record to temp

set applescript's text item delimiters to {","}

-- in case there is existing data in the portal

copy (cell "Relation::targetField" of current record) as list & text items of temp to temp

copy temp to cell "Relation::targetField" of current record

-- blam you're done

-- the whole "column" written in one shot

This topic is 7726 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.