Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

I am trying to write a script that either finds an existing record or creates a new record if no records are found. The script is initiated by clicking a "New Record" button which brings up a Custom Dialogue where one can enter "Surname", "Name" or "DOB". Clicking "OK" initiates the Find procedure. Clicking "Cancel" exits the script... The basic find/Cancel/New Record script is easy...

Enter Find Mode []

Show Custom Dialogue ["New Record"; (text instruction)]

If[Get(LastMessageChoice) =1]

Perform Find []

Else If [Get(LastMessageChoice) = 2]

Enter Browse Mode

Exit Script []

End If

If [isValid(Surname)]

Exit Script

Else

Enter Browse mode []

New Record/Request

Show All Records

End If

However, if a user wants to go straight to (create) a New Record without typing a name into the Custom Dialogue (by leaving fields blank and simply clicking "OK" (then in the "...no valid criteria..." dialogue box) > "Continue" (or "Cancel"), then a New Record is NOT created - the script just exits.

I know I could instruct users to enter a "name" no matter what (even a single character will do it), but users get upset when asked to do more than (ostensibly) is needed (clicking "New Record" > OK > Continue is already three steps when they somehow feel only one should be necessary to create a new record). It would be nice to be able to leave the custom dialogue empty and still end with a New Record.

Any suggestions would be welcome.

Rramjet.

Posted

Hmmm.... Given the resounding lack of response here, can I assume that it is a genuine bug in FMP10 - and that no solution is possible?

Posted (edited)

No.

If you wrote a script that didn't work you should assume you wrote a script that doesn't work and ask yourself what you did wrong.

This is a good reason to have FileMaker Advanced; you can step through the script and see what it does.

In your case first of all, you appear to have given incomplete information because attempting to perform a find with empty criteria will produce an error.

Secondly, you appear to be making an incorrect (invalid!) assumption about your isValid() test. What is it that you expect this to do?

IsValid tests to see whether the referenced field is a "real" field in the context of your test. An empty field is valid. IsValid() would return an error if you had referred to a field that did not even exist or that was not correct for the context. Or if you had the wrong data type for the field. Please look at FileMaker Help for is Valid().

For instance if you were in the Contacts layout and your script looked for isValid( InvoiceItems::Price ) THEN you would get an error because that field does not exist in the Contacts table and - presumably - is not related.

Edited by Guest
Posted

Ummm.... but the script works perfectly... and the IsValid() function is the precise function for the job because if the find request returns a valid field (even an empty one if that is the criteria searched for), then the script exits, it's as simple as that.

Hmmm ...so the find request with empty criteria will produce an error - but that's the precise problem here. Nevertheless you have made me realise that it is perhaps an insurmountable one. I just wish (in this instance) there was a way where a field simply left empty would search for an empty field - and not finding one would create a new record instead (according to the parameters of some script step(s) that I could insert in the original script).

However, I was in error in assuming a bug. I realise now it is in fact a FMP "feature" (that a find request with empty criteria will produce an error) that in this case prevents me accomplishing something I want. I can see why specifying = to find an empty field would be the way it is done in FMP, but simply leaving the field empty could be made to accomplish the same thing surely...? ...or perhaps I am simply asking the impossible.

Anyway, thanks for the reply BruceR.

I appreciate it.

Rramjet.

Posted

Why is this so difficult?

Show Custom Dialog

...

If [ IsEmpty ( field ) ]

Enter Browse Mode

New Record

Else

Perform Find

If [ not Get(FoundCount) ]

New Record

End If

End If

Posted

The script does not work perfectly. That's why you're here.

The only thing that appears to insurmountable is your attitude. You're not asking something impossible, you're asking to do something that is easy and quite common. There are many posts here on exactly the same subject, with successful results.

You just need to ask YOURSELF what you're doing wrong and what you need to LEARN in order to get the results you're looking for. There is no problem with FileMaker. There is no bug here. There is nothing within existing FileMaker scripting tools that prevents you from writing a valid script that does what you want.

It is a valid and quite useful feature of FileMaker that it produces an error and gives an error code for a variety of conditions, such as performing a search with no criteria. This is pretty much the same as any programming language.

The "set error capture on" script step and the get(lastError) command are both provided so that you can write scripts that deal with errors.

You can search for empty fields. The way you do this is by putting an "=" sign in the field while in Find Mode. If your users don't know to do that then you can adapt your script to do that for them.

Set Error Capture [ On ]

Enter Find Mode [ ]

Show Custom Dialog

If [ Get( LastMessageChoice) = 1 ]

If [ IsEmpty( yourfield ) ]

Set Field [ yourfield ; "=" ]

End If

Perform Find [ ]

If [ Get( FoundCount ) = 0 ]

New Record/Request

End If

Else If [ Get( LastMessageChoice) = 2 ]

Enter Browse Mode

End If

Posted

Wow... who did I offend? The terse and condescending replies here indicate that I must indeed have committed a grave offense. I sincerely apologise if I have. I did not mean to offend in any way at all.

Thank you for the above suggested solutions, I will experiment and get back to you as to their applicability in this case.

Rramjet

Posted (edited)

Solution Found :)

Not sure if all steps necessary - no time to clean it up just now... It works and that is the main thing.

Working from Comment's suggested script steps and my original I get:

Enter Find Mode []

Show Custom Dialogue ["New Record"; (text instruction)]

If[Get(LastMessageChoice) =1]

If[isEmpty (Surname)]

Enter Browse Mode

New Record/Request

Exit Script

Else

Perform Find[]

If[Get(FoundCount)=0]

Enter Browse Mode

New Record/Request

Exit Script

End If

End If

Else If [Get(LastMessageChoice) = 2]

Enter Browse Mode

Exit Script []

End If

Show All Records

Appreciate your scripting suggesrions Comment and BruceR.

Best regards,

Rramjet

Edited by Guest
Posted

My reply may have been terse, but it was certainly not meant to be condescending. I do sometimes roll my eyes when a simple problem is not solved quickly enough - this is not necessarily directed at you. That said, I also tend to roll my eyes when a flaw in logic is automatically presumed to be a bug...

Posted

That said, I also tend to roll my eyes when a flaw in logic is automatically presumed to be a bug...

Yep, that's a big eye-roller for me too.

Posted

Okay - I apologise again. I totally understand the eye-rolling. I was naive and hasty in my use of terminology. I will try to be more thoughtful when posting in future.

Rramjet.

Posted (edited)

Glad this is working for you. A few more points.

Your script as written will defeat the find and show all records if the find is successful.

The exit script statements are not needed.

It includes an extra End If.

It will need a Set Error Capture On statement.

Enter Find Mode []

Show Custom Dialogue ["New Record"; (text instruction)]

If[Get(LastMessageChoice) =1]

If[isEmpty (Surname)]

Enter Browse Mode

New Record/Request

Else

Set Error Capture On

Perform Find[]

If[Get(FoundCount)=0]

New Record/Request

End If

Else If [Get(LastMessageChoice) = 2]

Enter Browse Mode

End If

Edited by Guest
Posted

Hi Bruce -

Yes, the Show All step was a mistake and does indeed defeat the find.

The Set Error Capture is a useful step (I was tossing up between reinforcing to the users the find was unsuccessful by allowing the dialogue to appear, but considering my goal of minimising the number of "clicks" a user has to perform I will include the step). Thanks you.

I will re-examine the necessity of the all the "Exit Script" steps...

However, your current formulation cannot be operationalised because the If > If > Else > End If > Else If > End If structure throws up an "Invalid Script Step" at the Else If stage (missing an "End If" in the middle there) - but after including it something strange happens when a record is not found (after searching for a surname not in the database) and a new one is created... FMP tells me that even though it looks like a new record is created, it does not actually exist... I have to manually sort the records (by twice (!) clicking on the (now) greyed out FMP Total/Found records indicator button) before it appears... weird ...and then of course it is lost in the pack...).

Anyway thanks for taking the time to put forward your suggestions, they have definitely provided me some useful tips (and something to think about as to why your solution behaves in the weird manner it does :)

Best regards,

Rramjet

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