Jump to content

Where to put the "Error Capture" script steps


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

Recommended Posts

Hello All again,

My solution is almost 100% complete, just tidying up a few things, so thank you all who helped me along the way with advice.

On to the next question...

I have a script which finds all jobs quoted in the last 7 days (see "find Script" screen capture attached) - this script works well.

I have written an Error Capture script which seeks to identify "no records found" in a find enquiry (see "Error Capture" screen capture attached).

I want to introduce the Error Capture script into the find portion of the script, but I am not sure where to put it.

What I want from the script is ...

Start the lookup,

if records are found, compile the records as per search criteria and present then on the "View Lost Jobs" layout.

if no records are found, I have a dialouge box which tells the user that there were "no records found", and provides an OK button which escapes back to the "Home" layout

Both the Find and Error Capture scripts work independantly, but I just can't seem to find the order they need to be in to work together. I am aware I would probably need an else or else if step in there somewhere?

Any advice would be greatly appreciated.

Also, if there is any asistance that could be given to my previous post (User selected fields in a report) that would also be fantastic.

Cheers

Find Script.jpg

Error Capture Script.jpg

Link to comment
Share on other sites

Hello All again,

My solution is almost 100% complete, just tidying up a few things, so thank you all who helped me along the way with advice.

On to the next question...

I have a script which finds all jobs quoted in the last 7 days (see "find Script" screen capture attached) - this script works well.

I have written an Error Capture script which seeks to identify "no records found" in a find enquiry (see "Error Capture" screen capture attached).

I want to introduce the Error Capture script into the find portion of the script, but I am not sure where to put it.

What I want from the script is ...

Start the lookup,

if records are found, compile the records as per search criteria and present then on the "View Lost Jobs" layout.

if no records are found, I have a dialouge box which tells the user that there were "no records found", and provides an OK button which escapes back to the "Home" layout

Both the Find and Error Capture scripts work independantly, but I just can't seem to find the order they need to be in to work together. I am aware I would probably need an else or else if step in there somewhere?

Any advice would be greatly appreciated.

Also, if there is any asistance that could be given to my previous post (User selected fields in a report) that would also be fantastic.

Cheers

Hi,

I'm not sure why you'd need an "error capture script". In general I set Error Capture on at the very beginning of a script . . . even before a "GoToLayout" step. Setting Error Capture to "on" lets you capture and deal with whatever errors may occur. This can be seen as an advantage or "another tool" available to you in the course of your script-writing.

My 2 cents,

RW

Link to comment
Share on other sites

In general I set Error Capture on at the very beginning of a script...

Not a good idea. You want to know when there is an error. The idea is to trap for them in the script and take appropriate action so that the user never sees them.

Link to comment
Share on other sites

Not a good idea. You want to know when there is an error. The idea is to trap for them in the script and take appropriate action so that the user never sees them.

Thanks Rick, I placed it at the top of the find script as per your suggestion, but I still got the standard FM error message before my custom dialogue box.

It seems that it needs to go somewhere within the find script to work?

Vaughan, what you describe is exactly what I want to achieve. When there are no records to import that meet the search criteria,I want my custom dialogue box to tell the user there are no records, then direct them back to the main menu layout with just an OK or Continue button.

Alternatively, is there a way to modify the standard FM dialouge box to just have "continue" as an available option and have "modify find" and "cancel" diablebled?

As I said in my previous post, I have experimented with the positioning of the Error Capture script, but I cant find a position for it where it works. I have attached both the find and the error script steps that I have written, if you could help me by showing me where I should put the steps, I would be very grateful.

Error Capture Script.jpg

no records box.jpg

Find Script.jpg

Link to comment
Share on other sites

I believe your issue may lie elsewhere. I am a bit confused regarding which script to refer to, so let me take the blue one in "Error Capture Script.jpg".

It starts by setting error capture on, then it tries to perform find with no criteria specified. If error capture were off, you would get a dialog asking you to either modify the find or cancel it. Since you have error capture on, the dialog is suppressed and the find is canceled. In short, nothing has happened so far (other than generating error 400). The found set has NOT changed, so the rest of the script is irrelevant.

BTW, it is not necessary to store the last error or user choice in fields (and they better be global fields if you do). You can refer to them directly or store them in script $variables.

Link to comment
Share on other sites

Not a good idea. You want to know when there is an error. The idea is to trap for them in the script and take appropriate action so that the user never sees them.

Hmmm . . . isn't that why you'd set Error Capture ON? I think we're saying the same thing. Maybe I'm missing something. (EDIT) Of course . . . I see what you're saying. When writing a script you want to see the errors and trap for them, yes. I mean when a script is working properly the Set Error Capture step should be at the beginning in many cases, because almost ANY script step can, under the right (wrong?) circumstances, throw an error. Even a simple GoToLayout if the layout doesn't exist.

RW

Link to comment
Share on other sites

No, what I mean is you should be trapping for errors every time you create a new record or edit a record, and act accordingly. Do NOT assume the action will occur without error. For this you need error capture on, but turn it off after the action is complete.


set error capture [ on ]

open record/request

set variable [ $error ; get( lasterror ) ]

set error capture [ off ]

If [ $error = 0 ]

Set Field [ field1 ; something ] 

Set Field [ field2 ; something else]

...

Commit Record/Request [ no dialog ]

Else

#error editing record

#do something appropriate like end the process

#or pause and try again

End If

Now in this code we have trapped for the possibility that the record cannot be edited. But what if the record fails validation and cannot be committed? As the code is now FMP will pop up an alert asking to revert the record. The developer/user will see this and quickly work out that there is a problem. If error capture was left off on then the error won't be noticed and something quite unexpected may happen further down the process, such as records unexpectedly being deleted because a related record was not created, or something.

I worked on a commercial system a couple of years ago where every script began with error capture off on. I had a support call one day where the database had stopped working. It turned out the night before the lead developer had performed a major update to the database and re-imported all the data from the old to the new system, but failed to import the primary keys for the table! Had error capture been left off then we'd have been given warning by the system that the GTRR and other steps were not working because the primary key was empty. (BTW I worked this out only after turning error capture off and running the script and seeing what happened.) It was also a good reason to validate primary keys as not empty.

It's like covering the "check engine" warning light in your car with black tape because it keeps flashing. You NEED to know when there are problems, especially the unexpected ones you haven't trapped for...

Link to comment
Share on other sites

No, that's correct. From the script reference:

"On" suppresses FMP alert messages and some dialog boxes...

"Off" re-enables the alert messages.

Ahh... in my discussion after the code I have them switched around. The code is correct but my discussion is wrong. I'll edit the discussion.

Link to comment
Share on other sites

A couple of things:

1. Show All Records and then Constrain - why bother? Just do a normal Perform Find, it acts on all records.

2. When you Set Error Capture (ON), FileMaker error dialogs are suppressed. So yes, you would show your own dialog. E.g.:

Enter Find Mode

Set Field ( ... )

Set Error Capture (ON)

Perform Find

Set Error Capture (OFF)

If( Get( FoundCount ) = 0 )

. Go to layout(Main)

. Show Custom Dialog(...)

. Exit Script

End If

#

... continue your script here...

PS: Michael, I think there was search criteria specified, it's on the cut-off line at the top.

Link to comment
Share on other sites

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