Jump to content

Question

I have a script lthat is supposed to copy some fields from a related record. So far I have gotten it to copy and paste one field but, when it should copy and paste the second field it just falls through without performing the paste instruction. I have attached the file...the script in question is named "New Script"...the problem manifests itself at instruction 8 (Step 2) where it places the curser in the proper field, but then just bypasses the paste instruction (step 13).

 

Maybe I am going about this all wrong, but this is how i approached it.

 

Any and all sugestions appreceated.

 

Password for the attached is null/

DB 10:6.fmp12.zip

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

I can't get it to open. Be advised that this forum's software does funny things with "". Check if the post text matches what you typed.

Share this post


Link to post
Share on other sites
  • 0

None of these combo of Account + Password open the file:

 

"Admin" + "null"

"Admin" + "null\"

"null" + no password

"null\" + no password

 

-----

 

But without even opening your file, I can tell you that if you are using "Copy" and "Paste" to move data around in a FileMaker file, and you are using a version of FileMaker newer than version 2.1, you are going about it wrong. "Copy" and "Paste" are the kind of script commands you should be using on average about once every 3 years, usually to put something on your clipboard that needs to get pasted into some other non-FileMaker environment. There's never a good reason to use "Copy" or "Paste" to move data from one place to another within FileMaker.

 

• screws up the user's clipboard;

 

• you can only move one little chunk of data at a time

 

• requires the source field and the target field to be on the layout at the time you issue the command

 

• isn't versatile: you can't manipulate data using a formula such as adding or averaging numbers, all you can do is a straight one-to-one transfer of data; since other ways of moving data allow you to do either a straight one-to-one data transfer or additional data manipulation, copy + paste is redundant and klunky

 

 

Most commonly, you should use the Set Field command, either by itself (in situations where you are moving data from one location to a location that is related), or in conjunction with Set Variable (which you use like a virtual scribble-sheet or the back of a napkin, jotting down data that you're going to refer to later). You can perform multiple Set Field operations without bouncing around:

 

Set Field [YourTable::Field X; Related Table::Field A]

Set Field [YourTable::Field J; Related Table::Field C + Field D]

 

or if the tables are not related,

 

Set Variable [$Value To Copy; Some Table::Field Z]

Set Variable [$Another Value to Copy; Some Table::Field C + Field D / 12]

Go to Layout [some Other Layout]

Set Field [YourTable::Field X; $Value To Copy]

Set Field [YourTable::Field J; $Another Value to Copy]

 

 

 

-----

 

Having said that, your most likely scenario for your described copy-and-paste issue is that you either did not navigate back to the place you need to be to copy the data properly, or did not then navigate once more back to the place you need to be to paste it, or the two fields in the second copy-paste operation are missing from one or the other of the layout(s) where you're trying to copy and paste.

Edited by AHunter3

Share this post


Link to post
Share on other sites
  • 0

Damn I'm feeling stupid. The file I sent should have opened with a user name of "John"; then a null return for the password should have opened it. Don't know whay it didn't work.

 

However you must be right about using Set Field instead. I tried that first but it did not work. I tried it again just now and it still does nothing. I am attaching a new copy of the file. I really hate to ask, but would you please look at the script titled "New Script" and tell me what I am doing incorrectly?

DB 10:6 2.fmp12.zip

Share this post


Link to post
Share on other sites
  • 0

New Script

 

#Step 1

 

New Record/Request

 

Go to Layout [CLIENT DATA]

 

Copy [select; CLIENT DATA::ID #]

 

Go to Layout [DAILY GRID SHEETS Copy (Grid Data) ]

 

Go to Field [Grid Data::ID #]

 

Paste [select; GRID DATA::ID#]

 

 

#Step 2

 

Go to Layout [CLIENT DATA]

 

Copy [select; CLIENT DATA::Name~Full]

 

Go to Layout [DAILY GRID SHEETS Copy]

 

Go to Field [Grid Data::NAME~FULL]

 

Paste [select; GRID DATA::NAME~FULL]

 

NAME~FULL is defined as NAME~FIRST & " " & NAME~LAST.

 

That's not your only problem though:

 

If you started off on Client Data, you just pasted a completely blank value into this field, see above. If, on the other hand, you started off on a different table's layout, you are pasting whatever full name was on whatever random record you happened to land on when you went to CLIENT DATA in the second script step. As for the target record in Grid Data, it is possible that you started off on this layout, in which case you are pasting INTO the blank record you created in the first script step, but what you paste may not be from the record you intended to paste from; or, if you did not start off on a Grid Data layout, you are pasting into whatever random record you happened to land on, which may not be the record you intended to be updating here

 

---------

 

Do you see that context is a big problem for you here? It's a problem for me trying to answer your questions (because I am not a mind reader and don't know what context you invoke this script from -- there is no button for it anywhere, and you didn't say).

 

But it's also a problem for YOU. You are moving data from one table (Client Data) to another (Grid Data), but you are controlling which record is involved only in one of the two tables (whichever one you're staring at when you invoke the script). In that table, you are creating a new blank record. If it's Client Data, you created a new blank record to copy data FROM. If it's Grid Data, you created a new blank record to copy data TO. But whichever table it is that you made a New Record in, the other table being referenced in your script isn't necessarily aimed at the appropriate record. It could be any record. Let me give you some examples.

 

• Pretend that you just opened your database up from scratch and it opened to Opening Page (a layout showing records from Client Data). It happens to be on record 12 out of 48 Found, out of 234 total record, ID# 1124. Not that it shows you that on Opening Page. Your script will make a new blank record in Client Data and then when it copies data to a record in Grid Data, the record it lands on is the first record of 2 total, which currently has an ID No of 1124. Your script will overwrite this record.

 

• Pretend instead that you just opened your database up from scratch and it opened to DAILY GRID SHEETS Copy (that's where the last posted copy opens to to start out). It has a found set of 0 records. Your script will make a new blank record. Then it will navigate to Client Data. It happens to be on record 12 of 48 found, of a total of 234 records, and this is ID# 1124. But unless you always did something manuallly to put yourself on the appropriate record, on that layout, first, and then manually navigated to DAILY GRID SHEETS Copy and only then invoked your script, you would be copying from a random record, whatever record you (or the previous user) just incidentally happened to have been on in Client Data when they closed the database.

 

 

I am going to upload a copy of your database using Set Field to show you how it works.

Edited by AHunter3

Share this post


Link to post
Share on other sites
  • 0

Sorry, I tend to leave such niceties as buttons, script documentation, etc. until I have a semi-working solution. The file is intended to gather data from hand markups of the daily grid sheet, then use that data to generate a periodic report.

 

The problem is that if the client data is not static (i.e. a person may be changed from one distribution day to another, or the bag/box count may change if the number of adults. children or over 55s changes). I wanted to translate the data

 

from a grid sheet markup to a file whose numbers would not change, and thus could be used at any future time to make the calculations needed for the report. Yes, it's muddled thinking, but I know what I want to do with the data once I

 

have it in the format I want.

 

I orginally tried, unsucessfully. to use Set Field but obviously did not know what I was about. That was how I got to trying the copy/paste solution. Now that I see your reply, I can see how to go about it properly.

 

Your script works, and I certainly will use it with further adaptations. Two querstions:

 

The two data sets (Client Data) and Grid Data) are already related in the Tabke Relationships panel, so is it still necessary to re-establish that relationship in this script?

 

Your script transfers NAME~FIRST and NAME~LAST; why can't it just transfer the concatenation NAME~FULL?

 

Thanks again for all your help, I really do appreciate it.

Share this post


Link to post
Share on other sites
  • 0

 

The two data sets (Client Data) and Grid Data) are already related in the Tabke Relationships panel, so is it still necessary to re-establish that relationship in this script?

 

Only if you need to get away from records in Grid Data having the same Client Pickup Date as the corresponding (source) records in Client Data. If you're fine with every new rec created in Grid Data always have the Client Pickup Date that's in Client Data, just use the relationship you've already got.

 

Your script transfers NAME~FIRST and NAME~LAST; why can't it just transfer the concatenation NAME~FULL?

 

Because, as I said, NAME~FULL is a calculation field.

 

You can't change the value of a calculation field. If it is defined as NAME~FIRST & " " & NAME~LAST, you can't modify it to contain something that is anything other than the value that is in NAME~FIRST, & " ", & NAME~LAST. What you were trying to do — if it could be done — would have left you with a record containing a name in NAME~FULL while still being empty in both NAME~FIRST and NAME~LAST. And that's impossible: the calc field is defined as consisting of NAME~FIRST & " " & NAME~LAST.

Share this post


Link to post
Share on other sites
  • 0

Just realized that I defined the fields for the target layout improperly (so much for copy/paste in creating field names, duh). So I changed all the fields in the GRID DATA layout to Text and now it works.

 

I'll try notto bother you again.

 

Regards,

 

John

Edited by Jabert

Share this post


Link to post
Share on other sites
  • 0
Still confused. The step is not trying to change the value of a calculation. It simply wants to place the current value in a field on the new layout. Also, the value of Name~Full is fixed and never change once the calculation is made.

 

You are wrong. The step IS TOO trying to change the value of a calculation.

 

If NAME~LAST is blank (which it is) and NAME~FIRST is also blank, what is the outcome of this formula? Do it manually:

 

NAME~FIRST & " " & NAME~LAST

 

What's your answer?

 

It isn't "Bernard Denis", right?

 

Now watch what your script is trying to do: It goes to a record in Client Data (ID # 1123 in our previous example); in your original script you have it Copying the NAME~FULL field. The NAME~FULL field in this Client Data record happens to contain "Bernard Denis".

 

Then you go to the empty record in Grid Data and you attempt to Paste. What would you be pasting? "Bernard Denis", right?

 

If it allowed you to do that (which it doesn't), you would end up with "Bernard Denis" in the calculation field even though NAME~FIRST and NAME~LAST are both still empty. Do you see why that would be a violation of the formula for NAME~FULL?

 

"Bernard Denis" does not equal " ".

Share this post


Link to post
Share on other sites
  • 0
Just realized that I defined the fields for the target layout improperly (so much for copy/paste in creating field names, duh). So I changed all the fields in the GRID DATA layout to Text and now it works.

 

I'll try notto bother you again.

 

Regards,

 

John

 

Aah, you didn't realize it was a calc field!

 

That explains a lot :)

 

 

I still suggest that you ditch Copy and Paste and use Set Variable and Set Field instead. But glad you've got it working.

Share this post


Link to post
Share on other sites

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


×