KurtW Posted July 15, 2004 Posted July 15, 2004 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
DanBrill Posted July 15, 2004 Posted July 15, 2004 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
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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
MoonShadow Posted July 15, 2004 Posted July 15, 2004 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.
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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
MoonShadow Posted July 15, 2004 Posted July 15, 2004 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.
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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?
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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.
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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
DanBrill Posted July 15, 2004 Posted July 15, 2004 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. HTH, Dan
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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?
DanBrill Posted July 15, 2004 Posted July 15, 2004 Can't see why. If it still isn't working, can you post an example?
MoonShadow Posted July 15, 2004 Posted July 15, 2004 "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.
MorFologist Posted July 15, 2004 Posted July 15, 2004 what's the Trips: relationship based on? Could it be eliminating the other record?
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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. 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.
KurtW Posted July 15, 2004 Author Posted July 15, 2004 Okay, I have attached a .gif screenshot of that script portion since I can't cut-n-paste script elements.
merlyn383 Posted July 15, 2004 Posted July 15, 2004 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.
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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.
KurtW Posted July 15, 2004 Author Posted July 15, 2004 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
Crag Posted July 15, 2004 Posted July 15, 2004 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?
Miguels Posted July 16, 2004 Posted July 16, 2004 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.
Recommended Posts
This topic is 7438 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 accountSign in
Already have an account? Sign in here.
Sign In Now