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.

Featured Replies

Hi, i am using this script i found in the forum. Problem is that it only duplicates the first found record and not the complete set. Any help ??

Unsort Records

Go to Record/Request/Page[ First ]

Set Variable [ $recordPosn; Value:1 ]

Set Variable [ $foundCount; Value:Get(FoundCount) ]

Loop

Duplicate Record/Request

Set Variable [ $recordPosn; Value:$recordPosn + 1 ]

Exit Loop If [ $recordPosn > $foundCount ]

Go to Record/Request/Page [ $recordPosn; No dialog ]

End Loop

To leave only the duplicates, add these two lines at the end of the script.

Go to Record/Request/Page[ First ]

Omit Multiple Records[No dialog; $foundCount]

Hi Julio,

It is easier to take advantage of a sorted set because it holds the new duplicated record in position. I would suggest this script:

Sort [ by anything , no dialog ]

Set Variable [ $count ; Get ( FoundCount ) * 2 ]

Go To Record/Request/Page [ first ]

Loop

Exit Loop If [ Get ( RecordNumber ) ≥ $count ]

Duplicate Record

Go To Record/Request/Page [ next ]

End Loop

edited ... I changed >= to ≥ to avoid confusion although they will work the same.

Edited by LaRetta

Oh, if you need to end with only the new record set, add this outside the loop at the end:

Unsort

Go To Record/Request/Page [ First ]

Omit Multiple [ $count / 2 ]

This script produces less jumping around (back up to the top) and I believe it will be faster than the unsort method.

  • Author

Thanx, here is what i am doing. First a run a report layout and find records from a specific date, then i run the script but i get only one record duplicated infinitely ??

Thanx again

Does the attached work? Both scripts should work fine. I suspect you have the wrong perspective for the layout or you have misnamed one of your variables somewhere along the line.

I don't know what this points to ... webkit-fake-url://CBA50139-ED61-43BE-8A1C-776022DF38CE/image.tiff ... because it doesn't work for me, sorry. :^)

dup.zip

Edited by LaRetta

  • Author

?do=embed' frameborder='0' data-embedContent>



?do=embed' frameborder='0' data-embedContent>

You have Go To Record/Request/Page [ FIRST ] again at the end ... and it should be NEXT. :^)

  • Author

Thanx, my mistake works well. Only one thing left is that I need the new set to have a different date. For ex. I do a find on a set for march 1, and I would like the new dup set to have april 1 as the date for all records found !!

thanx again

WHOA, my mistake! I knew unsorted sets are faster but I assumed that omitting the need of jumping from end to beginning would more than offset the sort slowdown but not so. I just tested it. So stick with the original script. My apology for almost steering you wrong.

You do not want to hard-code that date so use a global and enter the date before you begin, or ask for the date in custom dialog. Let's assume you used a global field called gDate. After your script isolates the new records, use Replace Field Contents [ your date ; gDate ] - only if not multi-user. If multi-user, include step

Set Field [ your date ; gDate ] ... immediately after you duplicate your record.

As an aside for anyone interested, a sorted set slows down exponentially as the record number increases. I had reported the issue when 7 first came out and I was sure they had fixed it - I know it was fast again in vs. 8.0v2. But here is my current test with 4,000 records, Windows XP Professional, FMPA 11.0v3:

Original script (unsorted) - 1:20

My script (sorted) - 5:14

  • Author

I am sorry i'm not that familiar with FM, is this something i add to my script ? once i have created the global ?

If you will ALWAYS want one month after, you can skip the global and set the field with calculation one month older than your find criteria. I don't know how you are currently handling the find but consider this:

Enter Find Mode [ pause for user input of the date of March 1, 2012 ]

Set Variable [ $date ; Date ( Month ( yourdateField ) + 1 ; Day ( yourdateField ) ; Year ( yourDateField ) ) ]

... then continue your script and use this variable to set the new date.

This will always produce the same day but 'one month' later than the User enters into the find. To try it out, enter 3/1/2012 into the date field on the new revised file.

dup2.zip

  • Author

Ok, i run the scipt. I entered the date 01/03/2012 (i am using the spanish calendar dates, first day/month/year. I does duplicate the records but still with the march date ?

  • Author

My date field is called "date_start" !! don't know if this makes a difference ?

How about export and import (then populate the date).

What does this represent in your system? Might be a data model issue.

  • Author



LaRetta's script works fine on her table, but when i import an try on mine the date does not change. I changed the layout name and field name to match mine (in my database) but still not working

Hi Julio,

Well it should work regardless, since we are using the Date() function. Try removing the /* and */ from the Set Variable[] step and below fix the Set Field[] by re-pointing to the correct same date field and save your script. The /* are for commenting out a portion and FM thinks your field is invalid - they came over with the script import.

When you respecify your date in both locations, does it work then?

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.