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

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

Recommended Posts

Posted

After running a Perform Find [Restore], I need to evaluate results of the Find. If no record is found, I want to add record to table on which Find was performed, or script will move to other table to load variable with value in next record on which to perform Find.

I've tried testing get(foundcount) = "" and get(foundcount) = " " but neither is returning expected value.

Running in debug, I know table BB has record with value "101" in field b. I start Loop from table AA, load variable with value in field a, in 1st record "101" Find should result in 1 record, so get(foundcount) should return value of 1 or "1", not a null as "" or " " should be read.

How can I solve this?

Posted

Hello

What you are looking for is

get(FoundCount) = 0

or

Get(LastError) = 401

Error code 401 means "No records match the request"

So either one of these will tell you if your find produced no found records.

Todd

Posted

Make sure that you have an Error Capture [On] Script step so that the user doesn't see the error message saying "No records found"

Posted (edited)

Thanks Todd for replying to my inquiry. Tried Get(LastError) = 401 and "401" for the condition where I knew the Find would result in no results.

The Get(LastError)=401 did not evaluate to true. Actually, it seems to = 0 (no error). I know that's wrong, as in step mode can see result of Find is nada

What else have I missed?

Also, thanks Martha for the ErrorCapture [on] reminder. That elemental I've already stumbled upon.

A neophyte FM user many years out of the game but with ideas for complex ways to solve problems. Do appreciate the simple as well, thankfully!!

Edited by Guest
Posted

Hi MarcZ:

We should be able to knock this out. Could you post your script or attach a copy of the file? It would help immensely.

After running a Perform Find [Restore] ... If no record is found, I want to add record to table on which Find was performed, or script will move to other table to load variable with value in next record on which to perform Find.... table BB has record with value "101" in field b. I start Loop from table AA, load variable with value in field a, in 1st record "101" ...

That's a pretty good number of "moving parts." Perhaps they're all necessary, but they're raising a few red flags for me. We'll have the best chance of solving it if we can see the script, but could you also describe in a broader sense where/how this routine fits into your database? There may be a more direct technique to accomplish what you need.

Hope to hear back!

Posted

Hi there,

Make sure that you test for the error in the step that immediately follows the perform find.

perform find

Get(LastError)

Get(LastError) returns the error for the last executed step. So if you have any steps that are happening in between they could be messing with your results.

Todd

Posted (edited)

hello you two,

am now testing with "get(FoundCount)" and learned that get is evaluating # recs in table on which performing loop, NOT table subject of "Perform Find [Restore]"

script order is this:

... (variables declared, given values

Set Error Capture [On]

Perform Find [Restore] //specifies 2nd tbl w criteria fr var

If [Get(FoundCount) = 1] //tested tbl already has rec w var value

else

insert new rec

End if

Unable to act reliably (via script) when I know item value tested is or present in 2nd table because get(foundcount) reports # recs in table being scanned (source of var values) NOT table upon which Find performed

Edited by Guest
Posted (edited)

Hey MarcZ!

hello, pls see original link for my attempt to better explain prob!

Unfortunately, your original post doesn't enlighten me as to exactly where this scheme fits in your design. I see the moves you're trying to make, but what is the goal? From what you written, it sounds like the whole routine could perhaps be solved with relationships and portals. If that's the case, you may be inventing additional wheels.

[L]earned that get is evaluating # recs in table on which performing loop, NOT table subject of "Perform Find [Restore]"

Red Flag #1 ... The script will need to open a new window based on a layout in the target table.

Red Flag #2 ... Are both tables in the same file or in separate files? Script variables cannot be passed across files; we have to use global fields in that instance.

script order is this:

... (variables declared, given values

Set Error Capture [On]

Perform Find [Restore] //specifies 2nd tbl w criteria fr var

You may be introducing a conflict here ... Variables are dynamic (by definition, I suppose that's why they vary), yet the Restore aspect of Perform Find is referencing a "snapshot" taken at a previous time. Consider instead going with the Enter Find Mode script step, followed by the necessary Set Field steps you need.

If [Get(FoundCount) = 1] //tested tbl already has rec w var value

Consider using "greater than zero" instead, in case the result of the search found two or more records.

You may have omitted it from your post, but don't forget to include an Exit Script step here.

else

insert new rec

Likewise, New Record/Request script step, and if this new record is intended to be related to Table AA, you'll want to populate the new record in Table BB with the relationship "keys" from Table AA.

End if

Again, the routine you're decribing has a hint of something else ... something for which there are likely other, more reliable techniques that already exist in FileMaker.

Edited by Guest
Posted (edited)

okay, I tried following your suggestion, thus:

Set Error Capture [on]

Go to Layout ["ADocs" (ADocs)]

Enter Find Mode [Restore] // pause+specify find req unchkd

Set Field [ADocs::Fnm; $DocsFnm] //specify target field chkd-calcd field passes var val

Perform Find [Restore] //specify find req unckd THIS LAST CHANGE seems to have resolved issue THANK U !

BTW, thank you again for all your help

I'm a newbe here--how did you assign your profile an icon?

Edited by Guest
Posted

BTW, thank you for all your help

You're welcome, MarcZ. Hang in there ... we'll get her done!

Set Error Capture [on]

fine

Go to Layout ["ADocs" (ADocs)]

okay ... could open a New Window if you don't want users to "lose" the original window

Enter Find Mode [Restore]

leave unchanged for now, but we may have to investigate this next

Set Field [ADocs::Fnm; $DocsFnm]

leave unchanged for now

Perform Find [Restore]

Get rid of the Restore option by unchecking the Specify find requests option. Otherwise, you're telling FileMaker to disregard everything you set up in the preceding steps.

However, MarcZ, I'm not optimistic that we'll solve it this go-round. Your earlier posts mentioned searching in Table BB, is that right? Yet, the script you're trying to build is referencing ADocs in several places. I may be confused about this, but we'll see.

If we're still stuck, it would help if you could post your file. It could save us many steps. If you haven't ever done this, it's pretty easy.

(1) Close your FM file.

(2) Go to Finder and right-click on your FM file and select Create Archive to create a ".zip" file of your database.

(3) From FMForums Help section ... If file attachments are enabled, when making a post you can click the "Manage Files" link. A popup window will open allowing you to browse and select file(s) off your hard drive (that ".zip" file you created), then click "Add". When finished click "Finished" and the window will close so you can continue making your post.

BTW, you still haven't explained the big picture here....

Posted

Thanks for encouragement, pointers! The got me through to end, just fine.

Had unregularized table data, was trying to fix.

My records need 1st to refer to event dates. Each {event date} forms part of a {summary}. The {summary} may show multiple {event dates}, has a unique filename, associated PDF image, retained in a container field).

This exercise was trying to build table of all unique {summary} filenames (with PDF image), in part to reduce size (speed performance) of other data table. In unregularized table, PDF image/filename was field in multiple {event date} records.

Loop wrote about earlier did the needed job.

I started building tables, storing data within without fully thinking out most logical structure, and it's been many many years since I've built a database, written any scripts. Am new to FM, and like it lots.

[color:red]Three new questions:

Question #1

In my Borland Paradox days, there was something called an array, essentially a variable with elements referred to with [#] representing a record. So ArrayVar[0] = tablename, ArrayVar[1] =field1, ArrayVar[2]=field2... It's a structure used in C++ and I'd bet other languages. [color:blue]Can't find similar lang-struct in FM!

I have a layout {L1} built from a Find combining related fields from 2 different tables (this forms a part of my 1st stab at building the DB--was based on organizing prin of {Summary}). I've now realized it'll be more prudent to use different structure (based on {event date}. Built new tables, and need to distribute field data from {L1} to new tables where there is 1->M, 1->M, 1-M relationship.

Seems slow (but maybe that's only true in debug mode) to declare vars, Loop on {L1}, store values, move to {L2}, insert new rec based on current var values moveto {L1} end loop.

Question #2

If I store filename of PDF image in Container field (referenced), rather than embedded (as am now doing), what do I need to do to be able to open PDF document referred to in FM table (without leaving FM)? I know it's possible to play music stored in a container field, within FM, open a Word document, etc (Word doc issue same as PDF doc, I think)

Quest#3

My table w container field now mostly has embedded PDF images. There's also a field storing name of embedded PDF. Is there a way, via script, I could automate changing container field to be referenced? Have manually changed a few, but there are a couple hundred.

Thanks again, so much. I know I'll learn enough to solve these problems, then find new ones to solve, presumably better able as progress! That's learning!

MarcZ

Posted

Hey MarcZ!

Thanks for encouragement, pointers! The got me through to end, just fine.

Glad it worked out! :beer:

Thank you for taking the time to describe your project. For your "three new questions," I'm going to suggest that you first do a little searching on FMForums. If you can't find any love through existing topics, post your questions as new topics. If they're in the "right" sub-forums, and due to the fact that they're "new," I think you'll have the best shot at getting some answers.

For the meantime, I can merely offer some indirect commentary on the following ...

Your question about arrays ... Without any knowledge of Paradox or C++, I just don't have a frame of reference to help translate those techniques into FM; however, my instincts tell me that it points toward relationships. Not sure how much you've worked with relationships. If you feel you have more to learn (only you know for sure), I strongly encourage you to read up on them. In my opinion, they are our "best friend" in FM. (In fact, your initial question about the script hints at the need for a relationship.)

Your question about PDFs and Container fields ... I've seen some topics here in FMForums in the last couple of weeks that deal with those questions. Can't remember the details, but some dutiful searching will get you there.

They way I understand it, FM for MacOSX can't "open" a PDF in the same way Windows users can. Instead, I think the embedded/referenced is exported to the user's desktop, then it's opened. Yet, I do remember one of those recent topics talking about using the Web Viewer of FM8.5 to display PDFs in a "live" sense. That's a pretty neat idea! There's a whole sub-forum for Web Viewer in the Presentation Layer category.

And there was another topic talking directly about obtaining the file reference paths for currently-embedded files. May be just what you're needing.

Sorry I can't be of further help on these questions, but you'll benefit from the input of other forum members if you (1) do some searching, then if you don't find what you need, (2) "fire off" some new topics.

Best of luck, MarcZ! I've enjoyed our exchange, and I'll try to keep up with your posts.

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