Skip 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.

Replace Field Contents

Featured Replies

Hi:

I have this script step:

Replace Field Content [Trips::TripStatus; Trips::gBilledText]

Error capturing, and inspecting the data, shows that the Replace isn't happening.

I know the global field gBilledText has data.

I know the step is firing because I have a debug placed.

I suspect it's the way I have chosen to replace the field that is wonky. My only practical choice was Replace With Calculated Result:. But I don't actually need any calculation, I just want the text 'Billed', so in the calculation area I just refer to the global field. Can I do that? FM gave me no warning upon closing the dialog to say otherwise.

Thanks

Kurt

Have you tried set field? Also, make sure you are using the commit record step at the end or else the changes will not stick.

Dan

  • Author

You know, I didn't use Set Field as FM literature seemed to say that changed ONLY the current record.

"...or click Specify to specify the field whose contents you want to replace."

and

"...Replaces the entire contents of the specified field in the current record .."

I couldn't find any ref to it working on the entire found set. I guess from your comment that it does. I'll have to try it.

I guess the Commit Record is a newer step? I don't recall it from older versions. (Think I had been using 4?) Will also add that in.

Thanks

Kurt

You must be on a layout (defined for that TO) and the field must be on the layout for it to work. A global to capture your information will work fine once you're on the field's layout. wink.gif

  • Author

MoonShadow:

Ah, so I can grab data from a global and use the Replace function in script as long as I am on a layout that has the replace field. Or did you mean all of the above should be sed with the SetField[] function?

Thanks

Kurt

You can use Replace Contents, although I usually use Set Field. I just wanted you to be aware of why Replace Contents was breaking on you. smile.gif

  • Author

Thanks again. Scampering off to try it now.

  • Author

Okay, I must be dense or missing something. I now do:

Set Field [Trips::TripStatus; Trips::gBilledText]

And it does Replace the text, but only in one record of a found set of two records. I decided to drop the Replace function I mentioned above as it seemed to me, from what you said MoonShadow, that Set Field[] would be an easier workaround.

What am I missing?

  • Author

Should also mention that I figured I misread your instructions about Set Field, so to be safe I set the script to jump to a layout that contains the field Trips::TripStatus BEFORE I fire the Set Field.

That didn't cange the result. Still only 1 of 2 records is changed.

  • Author

Lastly I went back to using Replace Field Contents and made sure, again, that I wind up on a layout that contains the field to be changed before I process the Replace, but that goes back to throwing an error. So I was closer with Set Field

Ah, I see some confusion.

SetField just changes one record. If you want to use it to change all of the records then you need to embed it in a loop, looping through each record, setting the value, and moving on to the next record. Replace will do all of them at once. I know you need the commit step with SetField. I'm not sure off the top of my head about replace. The field does not have to be on the layout for SetField to work. Again, I'd have to check on Replace, but I don't think it has to be. I'm sure it has to be for the InsertCalculatedResult step, but that's another story.

The advantage of the replace is that it does all of the records in one fell swoop. However, if another user has possession of a record, their record won't be affected by the Replace, and you have no way of know which record was missed. With the SetField in a loop technique you still can't change a record locked by another user, but you can capture the errors so that you know which records are missed, or set up a loop within a loop so that you don't go to the next record until one is changed. I haven't played with this in 7 yet, but I think you could send a message to a user telling them to release a record if they are locked onto it.

That should get you started -- or ready to shoot yourself. smile.gif

HTH,

Dan

  • Author

Thanks Dan:

So I was on the right track originally with Replace Field Contents. Good.

This is a single user DB so record locking won't be an issue. But do you have any idea what would make the Replace fail? Even if I need to have the field to be Replaced on the layout I meet that requirement now.

Do I need, for some reason, to have the [color:"green"] GLOBAL field physically represented on the layout?

Can't see why. If it still isn't working, can you post an example?

"Again, I'd have to check on Replace, but I don't think it has to be. I'm sure it has to be for the InsertCalculatedResult step, but that's another story"

FM Help on Replace Field Contents: If the specified field does not exist on the layout where the script is being performed, Replace Field Contents returns an error code which can be captured with the Get(LastError) function.

This is what is happening. Set Field[] doesn't require this, which is why I usually use it but does require a loop to set all records.

Not sure why it's giving you grief. It'd be good to see your file.

what's the Trips::( relationship based on? Could it be eliminating the other record?

  • Author

Notaclone: It's not a relationship. TripStatus is a field in Trips.

MoonShadow: Maybe I am caught in semantics. "If the specified field does not exist on the layout [color:"red"]where the script is being performed... "

The script is initially run from a button on Layout A, where the field does not appear. The script goes to Layout B - where the field does exist - and finishes on layout C.

Now, the global field that carries the data to be used in the replace doesn not appear on any layout.

So, I'm not quite sure I have met the requirements for Replace. crazy.gif

I should also mention that all 3 layouts are based on Table: Trips.

Let me also try and cut-n-paste some code as a sample.

  • Author

Okay, I have attached a .gif screenshot of that script portion since I can't cut-n-paste script elements.

Script.gif

I'm fairly certain that you can't replace records in preview mode. Try either eliminating that or going to browse mode for the replace portion.

  • Author

Merlyn383:

I don't actually enter Preview mode until after the Replace is performed. Before the Replace is called, I only specify: Go To Layout [TripInput (Trips)]. Maybe it's possible that I am in still in Preview mode from the last call to Preview?

Could be. I will try your fix.

  • Author

Merlyn383 - right on!

I WAS still in Preview mode from last call. Switched to Browse and the Replace executes just fine. Many thanks. I would never have caught that!

Thanks to you all for your help!

Kurt

Just glad to be of service.

Let me ask a question related to this.. if he was gonna use Loop to step through all the records does FM end the loop at end of file? Or is there some way to test for last Record/End of File?

There is a checkbox "exit after last record" in FM6/7 when you select the "go to record/request/page" script and select next on the drop down menu a checkbox appears.

Ahhh, thanks.. i see it now.

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

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.