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.

A found count - need help

Featured Replies

Here's the situation - Two number fields with the names 'found' and count'. Whenever a sort occurs, this script is triggered.

Loop

ExitLoopif [count=(currentfoundcount)]

SetField [count, count + 1]

SetField [found, found + 1]

PerformScript [next]

End Loop

As you can see this will go through the search results and add one to the existing number. This, by the way, is to track what was found over a website. All works well but the last record found gets add whatever the found count was. Why is this happening?

Thanks

Rich

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

Rich

I'm afraid that I don't understand much of what you're trying to do with this script. Are found and count global fields? What do you mean by "the last record found gets add whatever the found count was?" by "(currentfoundcount)" do you mean "Status( CurrentFoundCount )" or is that another field?

Chuck

  • Author

Well, as I've said, this script will track what records have been found across a website. So when a search has been performed, each record found will get a +1 to it's 'found' field. This way I know how many times it's been accessed. But what is happening is the last record in the search is being added the status(currentfoundcount) to the number already there. The fields, count is global and is cleared at the end of the script. The found field is a number field.

Example:

A search for 'bars' comes up with 12 results. The script runs and each 'found' field in the search is added '1'. The twelth record is added '12' - So if the last record had a number of 10, after the script it would be 22, where all else would go to 11.

I think I forgot the status part of 'status(currentfoundcount) on the previous post.

Loop

ExitLoopif [count=status(currentfoundcount)]

SetField [count, count + 1]

SetField [found, found + 1]

PerformScript [next]

End Loop

Clear[select, count]

Hope this help.

Thanks

Rich

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

Rich

Firstly, I'm assuming that what you posted is the entire script, because if it's not them my suggestions might not work...

What does the "Next" script do? If this script does nothing other than move to the next record then dump it and use the Go to Record step instead -- in which case you can delete the Exit Loop step too...???

Loop

SetField [count, count + 1]

SetField [found, found + 1]

Go to Record [next, exit after last]

End Loop

I'd pop a Go to Record [First] script step just before the loop to make sure the loop processes all of the found set.

My first thought is that the field count is not a global field. If it is a number field, then the behavior your are getting makes sense.

If the count field exists only to tell you when you need to exit the loop, then Vaughan's script should do what you need, and you can actually take out the Set Field [ count, count + 1 ] step.

If the PerformScript [ next ] does more than simply a Go to Record/Request/Page [ Next ] then you could add a line at the beginning of the loop to Exit Loop If [ Status( CurrentRecordNumber ) = Status( CurrentFoundCount ) ]

Chuck

  • Author

OK, the latest script, now does not add to the last record. Here it is.

Go to Record/Request [First]

Loop

ExitLoopIf [status(CurrentRecordNumber) = status(currentrecordfound)]

SetField[found, found + 1]

Go to Record [Exit after Last, Next]

End Loop

As I said, this script now does nothing to the last record. Do you think the EndLoopif is triggering the script to end on the last before it does anything to the found field?

I appreciate both Vaughn and Chuck for helping with this matter.

Thanks

Rich

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

Rich

Transpose the third and fourth lines:

Go to Record/Request [First]

Loop

  • Author

Chuck -

Thanks very much. As your website says, You are an expert in this field. It now works properly.

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

Rich

Wouldn't it just be easier to use the following for a script?

Replace [found, Replace data: Calculation:, found + 1]

That would work, I think, although there are certain script steps I tend to avoid unless there is no way around them. Replace is one of them. Copy and Paste are two more. I avoid Replace because it is layout specific, requiring the field to be on the layout when the step is run. This makes it easy to break the script later and not catch it right away. The Set Field step doesn't have this restriction.

Chuck

Good point. I learned my scripting back in the bad old days of FM2.0 when there was no setfield function. I always make a habit of jumping to a working layout at the beginning of every script. My working layout has every field on it, and it is hidden from the user. I usually prefer the replace function because it's generally faster than looping.

One of the databases that I inherited had looping scripts that actually took 4 days to run (about 65,000 records). I rewrote the script using the replace function and got the time down to just a few hours. Not great, but better than having the system unavailable for a week.

Which is faster, Replace or Looping? It kind of depends. A looping script with several SetFields can be faster than several Replaces. Depending upon the calculation, I've actually used a Replace AND a Loop in the same script to optimize speed. Testing helps. -bd

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.