Jump to content

Error when calling for FMP records


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

Recommended Posts

I've created a button "Burn DVD" when I click this the script down below is being executed.

If I run this code as an Applescript application everything works perfectly. However, when being executing within FMP by clicking the "Burn DVD" button, I get the error message "Cannot find the record". The problem seems to be with the statements :



  1. tell (every record whose cell "N°Invoice" is NoInvoice and cell "SN°Order" is Index Order)
  2. set filteredRecords to every record whose cell "N°Invoice" is NoInvoice and cell "SN°Order" is Index Order

What could be the problem ?

Or is there a way within FMP to run an application inside FMP with arguments?

Many thanks!

Daniel

Burn DVD is to Perform Applescript

set NoInvoice to cell "N°Invoice" of current record

set Index Order to cell "SN°Order" of current record

display dialog "Invoice: " & NoInvoice & " Index: " & Index Order



set the_list to {}

tell application "FileMaker Pro Advanced"

	tell database "wPZV"

		tell table "CustomerOrder"

			try

				tell (every record whose cell "N°Invoice" is NoInvoice and cell "SN°Order" is Index Order)

					set cell "Status" to "B"

				end tell

				set filteredRecords to every record whose cell "N°Invoice" is NoInvoice and cell "SN°Order" is Index Order

				set recordSet to {}

				repeat with i from 1 to (count of filteredRecords)

					set the_record to (a reference to item i of filteredRecords)

					set theOrder to (text 3 thru 3 of the_record)

					set the_list to the_list & theOrder

				end repeat



			on error

				display dialog "Cannot find the record"

			end try

		end tell

	end tell

end tell

Link to comment
Share on other sites

This above script is doing the following:

Find all records for a given NoInvoice & a given IndexOrder

tell (every record whose cell "N°Invoice" is NoInvoice and cell "SN°Order" is IndexOrder)

Substitute the status to "B"

set cell "Status" to "B"

NoInvoice IndexOrder OrderNo Status

123450 1 0101 C

123450 1 0102 C

123450 1 0103 C



to 



123450 1 0101 B

123450 1 0102 B

123450 1 0103 B





Loop through all records


set filteredRecords to every record whose cell "N°Invoice" is NoInvoice and cell "SN°Order" is Index Order
One record at a time add the OrderNo to the variable the_list
(set the_list to the_list & theOrder)
Set the variable set the_list to {} Read each record, one at a time Set the_list to the_list & OrderNo
In the end the variable the_list should be equal to 0101 0202 0303

What is the command in FMP which allow to read one record at a time? I think I have to loop through the result of a Find using the Go to Record/Request/Page <first/last/next>. Am I right?

Thanks!

Daniel

Link to comment
Share on other sites

Why AppleScript? Learn Filemaker.

The reason being that I must have something ready for January 20, 2011. At this time, part of the solution is working with Applescript programs.

I have to look at long and short term solutions. When comes the time to optimize some of the processes I will be recoding as much as I can in FileMaker pro.

First, I have to meet the January 2011 milestone. Then I will start to optimize the code and make the workflow more robust. My next milestone is for March 24, 2010.

Link to comment
Share on other sites

What an extraordinary non sequitur. That just isn't a realistic reason to avoid five minutes of work.

I agree with you thisis five minutes of work for someone who knows about scripting in FileMaker.

Like I've said I know NOTHING about filemaker pro. I am learning, I like the tool, I am happy about my choice of going with FileMaker Pro.

Why, am I asking questions on this site, it is because I need help.

Why not answering the question I've asked What is the command in FMP which allow to read one record at a time? I think I have to loop through the result of a Find using the Go to Record/Request/Page <first/last/next>. Am I right?

Maybee that would be a good way to help me to think FileMaker before applescript.

Just an idea !!!

Link to comment
Share on other sites

The advice to you weeks ago, when you first started asking these questions, was to look at the template files that are already installed in your FileMaker app folder.

That advice still stands.

For example, attached see a PDF showing all scripts from the Invoice template.

Search for "Loop".

Invoice_Template_scripts.pdf

Link to comment
Share on other sites

I've looked at the pdf document and it does not have any example on the "Go to Record/Request/Page <first/last/next>"

Nevertheless, I've managed to rewrite the first part of my applescript program as a filemaker script (see attached)

my first read FMP script function

Now, the next step for me is to pass the value of the variable $the_list to the function Perform AppleScript which is to execute Toast Titanium.

For the time being in my AppleScript I am only executing the following vary basic operation.

I've tried to set the variable FMPrec to the variable $the_list and that does not work.

How can I pass the value of $the_list to the function Perform AppleScript?

set FMPrec to $the_list

set stringLength to length of FMPrec

repeat with i from 1 to stringLength by 4

   if stringLength - i < 4 then

       set nextpar to (text i thru -1 of FMPrec)

   else

       set nextpar to (text i thru (i + 3) of FMPrec)

   end if

   display dialog "Nextpar" & nextpar

end repeat

Thanks!

Link to comment
Share on other sites

1. The advice is to look at the template files and their scripts. I provided one such script as an example.

2. You can print the script to Preview; then save it as PDF. This make it an easily searchable document as in the example.

Link to comment
Share on other sites

1. The advice is to look at the template files and their scripts. I provided one such script as an example.

2. You can print the script to Preview; then save it as PDF. This make it an easily searchable document as in the example.

Is there a way to print all of the template files as one pdf document ? There must be 20 some templates provided with FMP each of them containing X numbers of scripts.

When I click OK button on I get this error message "Expected expression but found unknown token.".

I am going to try something else, in reading one of my previous topic, Fenton gave me an idea that I will be exploring during the day. What I am doing now is different then at that time. However, I there is a way to accomplish what I want to do.

Go to Layout [ “CommandeClient” (CommandeClient) ]

Set Variable [ $NoFacture; Value:CommandeClient::N°Facture ]

Go to Layout [ “CommandeOrdrePassage” (CommandeOrdrePassage) ]

Perform Find [ Specified Find Requests: Find Records; Criteria: CommandeOrdrePassage::N°Facture: “=$NoFacture” AND CommandeOrdrePassage::SN°Commande: “=1” ] [ Restore ]

If [ Get (LastError) ≠ 0 ]

Go to Layout [ “CommandeClient” (CommandeClient) ]

Beep

Show Custom Dialog [ Title: "Enregistrement non trouvé"; Message: "L'enregistrement recherché n'existe pas dans la base de donnée!"; Buttons: “OK” ]

Else

Go to Record/Request/Page [ First ]

Loop

Show Custom Dialog [ Title: "Enregistrement"; Message: CommandeOrdrePassage::N°OrdrePassage; Buttons: “OK” ]

Set Variable [ $$the_list; Value:$$the_list & CommandeOrdrePassage::N°OrdrePassage ]

Go to Record/Request/Page [ Next; Exit after last ]

End Loop

Replace Field Contents [ CommandeOrdrePassage::Status; Replace with calculation: "B" ]

[ No dialog ]

Show All Records

End If

Show Custom Dialog [ Title: "la liste"; Message: "la liste....:" & $the_list & ":...."; Buttons: “OK”, “Cancel” ]

Perform AppleScript [ Native AppleScript:

--set FMPrec to $$the_list

repeat with i from 1 to stringLength by 4

if stringLength - i < 4 then

set nextpar to (text i thru -1 of FMPrec)

else

set nextpar to (text i thru (i + 3) of FMPrec)

end if

display dialog "Nextpar" & nextpar end repeat ]

Link to comment
Share on other sites

So far about the only thing I really understand is that you want to change the status from "C" to "B", which you accomplished via Replace Field Contents (it could also be done with a Set Field step inside the Loop).

I don't know what you're doing with the other stuff re: the length of 4 and changing the IDs (or something). I'm pretty darn sure it could be done with native FileMaker functions. But I don't know what needs to be done (or whether there's a better structural idea).

I also don't see why you're showing a dialog within the Loop, ie., for every record. If you are doing that so you can see what is happening, then you should likely buy FileMaker Pro Advanced. It has a Script Debugger tool to watch scripts one step at a time (or stop points, etc.). Combined with a Data Viewer, you can see the result of each step.

Maybe it would helpful at this time to just tell us, in simple English, what you're trying to do; "why" would also be nice. It is obvious from the FileMaker script you wrote that you understand enough FileMaker to learn to do this with FileMaker native commands.

Link to comment
Share on other sites

Agreed with Fenton that it is very hard to understand what the point of all this is. Further, regarding the 4 digit codes, I supplied a completed standard FileMaker script was when all of this started.

Link to comment
Share on other sites

This topic is 4407 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
 Share

×
×
  • Create New...

Important Information

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