John Harris Posted February 6, 2003 Posted February 6, 2003 I am trying to copy data from a field in another file and paste it into the current file using a script. The data doesn't load into the clipboard in the following windows example: Create two databases, name one 'COPY' one 'PASTE' Create one field in each, name one 'NAME' in the 'COPY' file, name one 'ID' in the 'PASTE' file. Enter sample data into the 'NAME' field of the 'COPY' file. (e.g. FRED) copy some junk into the clipboard (e.g. hhhhhh) Define a relationship in the 'PASTE' file named 'copypaste' 'NAME=ID' Create a script in the 'PASTE' file named 'pastefrmcopy' script line 1: Copy[select, copypaste::NAME] script line 2: Paste[select,"ID"] run script ANY IDEAS ? I realise that there may be many work arounds, the one I am currently using is to copy in the target file and call an external subcript in the destination file which pastes from the clipboard, messy isn't it. I can use the set field command only if both fields are global.
Ugo DI LUCA Posted February 6, 2003 Posted February 6, 2003 Hi John, Are you are trying to copy "FRED" from the COPY file to the PASTE file ? If so, you just have to redfine your relationships as this will never work with Name::ID. Just read some thread here on relationship and you will understand why. Basically, a relationship is based on common fields content. You can have a relationship from COPY to PASTE if Name = ID, that is to say if you have FRED in both the Name and the ID field. In your script, FM will never end up into the Name Field, then no datas will be copied and the result of the Paste will automatically be the last previous clipboard paste. As you were in Paste file, with ID = " " (no datas in it), what you were asking FM to do is "go and check in COPY if there is a record " ", then paste it into PASTE". If even there was an empty field, no relationships can be defined on empty field, so FM will even never have pasted " " into the ID field. Tell if you do not understand.
jasonwood Posted February 6, 2003 Posted February 6, 2003 Also... If you have a relationship, you would almost never want to use copy/paste. Use "set field" instead. If for some reason you don't want a relationship, you could use copy/paste, but you have to copy in the source database ("COPY") and then run an "external script" in the target database ("PASTE") that pastes the data in the field. Ugo explained that the data in the match field must already match for a relationship to work. The only exceptions are when accessing data in global fields, and when creating related records (through a portal for example). In the second case, the data will automatically match immediately upon creation of the related record.
Ugo DI LUCA Posted February 6, 2003 Posted February 6, 2003 I can use the set field command only if both fields are global. Nope ! You can use setfield using a setfield(text=global) or setfield(global=text) or setfield(global=global). In addition to Jason's reply, one other reason why you should use set field and globals rather than copy/paste function is that the set field work within the file, while the paste work within the layout. This mean that you always have to identify the layout where the field you want to paste into is standing. If for some reason you removed the field from the layout after the script was created (as it is often the case while developping the database), your script will come up with a serious trouble. The setfield function is therefore again more appropriate, and much more secure. But just do read some more about relationships, as this is the starting point of FM (relational database).
spb Posted February 6, 2003 Posted February 6, 2003 Ugo is correct. SetField will work with any combination of global & non-global fields. SetField also doesn't need the fields displayed to work, while Copy & Paste require that the fields being copied from and pasted to be visible on a layout at the moment the actions are taken, so you have to add a Go To layout script step before each command to make sure you are there when it happens. I think your problem lies more in the relationships, as was said earlier. One way to get around this is to make a global in COPY, call it g_Name. Now make a constant relationship between COPY & PASTE. That is, make a field in each db that always contains a 1. Relate the two dbs on these fields, call the relationship ConstantRel, or something. You can't access specific records across such a relationship, but you *can* access global fields. Make a script in COPY that finds the record you want and sets the global with Set Field (g_Name, Name). this inserts the contents of the Name field into the global. Now, over in PASTE, you can set the name field (here called ID, I think) across the relationship with: SetField (ID, ConstantRel::g_Name) However, I wonder why you need to do this at all. There should be some kind of import procedure or other form of data cleanup that is quicker & easier. Maybe you could explain more fully what your data now looks like, and how you want it to look, and why you need two databases at all. Steve Brown
Pablo Ramirez Posted February 7, 2003 Posted February 7, 2003 Hello Couldn't you create a portal in the same layout that you want to paste data into. And then create a script that copies from the portal. The script could be: Go to portal Row[select, No dialog, By number (select the desired row] Copy[select, "origin field" Paste[select,"destination field"] Pablomac
Ugo DI LUCA Posted February 7, 2003 Posted February 7, 2003 Couldn't you create a portal in the same layout that you want to paste data into. And then create a script that copies from the portal. Hi, Pablo, He still needs to define a relationship...
John Harris Posted February 7, 2003 Author Posted February 7, 2003 Thanks to all, I am working my way through the information in the posts, but I thought I would explain what I am trying to do. I have two databases one is a list of names the second is a list of events. I want to be able to add a name to a field in the events database so I end up with a list in the events database of names involved in that event. The reason I want to use copy paste, is that the field in the events database will have a list of names seperated by a carriage return. I can then have a field in the names database which checks if that name is in a given event. The result is I can add an event then add a name to it and see if they are involved in that event. It's great to know you are all out there and are willing to help thanks thanks thanks. John
Ugo DI LUCA Posted February 7, 2003 Posted February 7, 2003 Ok, I was sure you were trying to perform this kind of stuff. Well, let's go into it. I've made an attachment as you can understand what is the process. You are right assuming you need a carriage return to have what we call a "Multikey". This could give you in a way certain results, but for what you are trying to do, you just need a third file. What is called a line item... A line item is a [color:"red"] "central file" that will "join" Name file and Event file together. As one particular person could be involved in many events, and as one event could have many participants, you will end with multiple records, like : - feb 03 - Mario on Indianapolis Show - feb 03 - John on Indianapolis Show - Dec 03 - John in New Year's Party ... Please note that this line item file [color:"red"] is not intended to the user , you would enter the data by "portals". You could even have only one layout with all fields listed in that file. Edited :OOPS . Error here...you will always print reports from line items, then you need to create these report layouts. But for entry, you won't need more than one layout... Here are the BASICS steps : - File EVENT will hold Event_ID (autoentered serial N
Recommended Posts
This topic is 7964 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 accountSign in
Already have an account? Sign in here.
Sign In Now