Jump to content

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

Recommended Posts

I am using FP7 and I am new to writing scripts, please bear with me as I try to verbalize my question.

I would like to create in one table, Table A, a button next to each record that would run a script to paste that record's data, from one field, into a field in another separate table, Table B. I have set up a relationship to match the two tables and fields, and I have tried creating a simple copy and paste script in Table A, but it isn't working. What part am I missing?

Link to comment
Share on other sites

Are the tables in the same file? Are the fields on the same layout? Are there any records in table B? What fields are you using for your relationship? What is the error message you're getting? Let's see your script.

In FileMaker 7 and earlier, we use global fields to move data from one place to another (in FileMaker 8 we use variables). This is better than copy and paste because for one thing you don't blow away the user's clipboard. E.g.:)

Set field( globalTemp ; Table_A_field )

...

{do whatever steps here}

...

Set field( Table_B_field ; globalTemp )

Link to comment
Share on other sites

The tables are in different files, the fields are on different layouts and yes, there are records in Table B. I am using a "company code" field for my relationship, so text, which matches both tables. I am not getting an error message, I'm just not getting the completed script. I have posted my script below. Note: Companychange and MaterChange1 are the names of the databases. I'm not sure why Mater1 is a different name at this point, but it is the same as MaterChange1.

Copy [select; COMPANYchange::Company Code]

Open File ["MATER1"]

Paste [select; MATERChange1::Company Code]

I can't use a global field because the data is different for each record. But the data is very small actually. . . only 4 digits.

Link to comment
Share on other sites

The Open File script step is using the name of the file, whereas the Paste step is using the name of the table; that's why the names are different.

What you will have to do to make it work is:

1. Make a script in the Mater1 file that does the Paste step. I recommend that you precede that step with a "go to layout" because the script will fail if the field is not on the layout (another reason to use Set Field instead). Let's call this script "Paste-fest."

2. Modify your original script like so:

Copy [select; COMPANYchange::Company Code]

Open File ["MATER1"]

Perform Script["Paste-fest" from file "MATER1"]

Now I must say that all you are doing is opening the file and pasting the company code into the first record. I.e., you're overwriting the existing company code in that record. Don't you want to make a new record or do a Find first?

Link to comment
Share on other sites

I can't use a global field because the data is different for each record.

I don't see what that has to do with anything. The point of the global is to use it instead of the clipboard.

But the data is very small actually. . . only 4 digits.

Again, that's beside the point. The point being, if a user copies some text, and then runs your script, the text she copied will be gone. Maybe that's not a factor for you.

There's actually a better way to do it, which is to make a Table Occurence in your source file (Companychange) that is based on your target table (MaterChange1). That way you can do the whole thing in one script consisting of one "Set field" step, and you won't need copy, paste or globals.

Link to comment
Share on other sites

Maybe I dont' really understand what a global is then. . .but if I can do this process with a Table occurence in my source file, then that would be great. . .However, I don't know how to make that work. And no, I'm not overwriting any of the company codes. . . this is all happening when I'm entering new data into the target table, MaterChange1.

Link to comment
Share on other sites

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