1 2 Previous Next 25 Replies Latest reply on May 31, 2011 4:22 PM by LaRetta_1

    Getting field value from one layout and putting it in the same filed in another layout

    jetmaster

      Title

      Getting field value from one layout and putting it in the same filed in another layout

      Post

      How do script so that I get the value of a field in one layout and put that value in the current record of another layout?

      relationships2.png

        • 1. Re: Getting field value from one layout and putting it in the same filed in another layout
          philmodjunk

          Each layout you create in your database is based in a table by specifying a table occurrence name in Show Records from in Layout Setup... for each layout.

          To what tables do your layouts refer? Is there any relationship defined between the two tables?

          Why do you need to copy the data in this fashion? (There may be a better approach.)

          Keeping in mind that your answers to the above questions may suggest that a different method may work better for you, here's a simple script that will do the job:

          Set Variable [$Value ; Value: YourTable::YourField ]
          Go To Layout [//select second layout]
          Set Field [YourOtherTable::YourOtherField ; $Value ]

          Note that this script makes no effort to select the correct record in the second layout's table nor does it create a new record--both are possible things your script may need to be modified to do depending on your answers to the questions I've asked here.

          • 2. Re: Getting field value from one layout and putting it in the same filed in another layout
            jetmaster

            OK I will explain in more detail.....

            I have an equipment layout with each record being an item of equipment in a laboratory. On that layout there is a button to add a NEW SERVICE record which takes you to a layout to add the details for a new service visit for the particular item you were on when you clicked the NEW SERVICE button.

            So, when you get to the new service layout the item is already filled in as is the vendor associated with that item (the field vendor::company which is a drop down menu with the value list being the field's values...so no EDIT LIST.)

            But it is possible that a different vendor may be doing this particular service...I want the user to be able to add a new vendor and then return to the service screen with the new vendor being the value selected for the vendor::company field.

            So I have a button that says CLICK HERE TO ADD A VENDOR

            the script for this button is;

            go to layout ["Vendor Detail (Vendors)]

            New Record

            Once at the vendor detail screen the user fills in the info for the new vendor then clicks on a button to go back to the NEW SERVICE screen which they were on, hopefully with the new vendor in the vendor::company field.

            The script for that button is:

            set variable [$companyID; value:vendors::__kpVendorID]

            go to layout ["service detail" (Servicing)]

            Go to record/page [last]

            set field [servicing::_kf_vendorID; $companyID]

            What IS happening as a result of all this is that a new service record is created BUT WITH THE ORIGINAL VENDOR IN THE COMPANY FIELD EVEN THOUGH THE NEW VENDOR IS IN THE VALUE LIST, JUST NOT SELECTED.

            Hope this makes sense.

            Relationship graph screenshot included on an edit of the orginal question...

            • 3. Re: Getting field value from one layout and putting it in the same filed in another layout
              philmodjunk

              I don't see a need for Go To Record/page [last] and it might be entering the CompanyID into a completely different record. It depends on which record is current on your Service detail layout when the user clicks the add vendor button. If it's not the last record in your found set, it won't work the way you need it to.

              Since your service and vendor layouts are based on different table occurrences (boxes in your relationship graph), the actions performed on one layout will not affect the found set, current record and sort order on the other and thus the current record on your servicing layout will stay the same record (on that layout) when the user clicks the button to add a vendor on the vendor layout.

              Thus, you should try this script again, but with go to record/page [last] removed or disabled. (disabling a script step requires Filemaker Advanced.)

              • 4. Re: Getting field value from one layout and putting it in the same filed in another layout
                jetmaster

                i removed the go to last record step but the result is the same......you go to the new service record, the new vendor is in the list but not the selected value in the drop down list.

                • 5. Re: Getting field value from one layout and putting it in the same filed in another layout
                  philmodjunk

                  How is your drop down list defined and in what field does the list enter a value? (Check your settings here as it sounds like it doesn't enter CompanyID number into the Servicing::_kf_vendorID field.)

                  • 6. Re: Getting field value from one layout and putting it in the same filed in another layout
                    jetmaster

                    the list enters a value in Vendor::Company

                    The list is defined by the values which comprise that field, and the options are to display both vendor::__kp_vendorID and vendor::company side by side....which it WAS doing but now all of a sudden it is ONLY DISPLAYING THE __kp_vendorID and not the company name....

                    I may need to go back a few saved copies....

                    • 7. Re: Getting field value from one layout and putting it in the same filed in another layout
                      jetmaster

                      got it back to where it displays id AND company name but still has original vendor and not the newly added vendor selected in the drop down

                      • 8. Re: Getting field value from one layout and putting it in the same filed in another layout
                        jetmaster

                        This seems to work (no key IDs, just regular fields:

                        set variable [$companyID; value:vendors::Company]

                        go to layout ["service detail" (Servicing)

                        set field [vendors::company; $companyID]

                        BTW is there a way to copy script steps to paste in a forum posting like this?

                        • 9. Re: Getting field value from one layout and putting it in the same filed in another layout
                          LaRetta_1

                          It is probably a refresh issue.  When you add a new vendor in the Vendor table, Services can accept the VendorID but the display of the Vendor Name is probably not updating.

                          Take the VendorID and place the field on your Services layout without the value list attached so you just see the number.  Then fire your script.  When you come back, has the number changed?  If it has (but the vendor name didn't change) then you need to include a Refresh Window [ Flush jcached join results ] at the end of your script.

                          If this doesn't resolve the issue then it would be helpful to see your file if you can upload it somewhere and provide a link here. :^)

                          • 10. Re: Getting field value from one layout and putting it in the same filed in another layout
                            philmodjunk

                            I just took another look at the relationships. You are creating a new vendor in vendors and then switching back to services to see a change in the services layout, but there's an intervening table occurrence ( and data source table ) in your relationship: Equipmnet and it is a record in Equipment that links to vendors by vendor ID. I can't tell from here if that's really the relationship you should have, but using what you show here, your script should be modifying a a vendor ID field in Equipment--not services.

                            That suggests you may need to make a change in your relationships unless a given equipment record can only link to a single vendor.

                            • 11. Re: Getting field value from one layout and putting it in the same filed in another layout
                              jetmaster

                              this does NOT work despite the above:

                              set variable [$companyID; value:vendors::Company]

                              go to layout ["service detail" (Servicing)

                              set field [vendors::company; $companyID]

                              A new vendor is created and added to the list but it also changes the value of the vendor::company field of the first vendor record (__kp_vendorID = 100) to this new vendor value replacing what was there...ugh!

                              I will try the last two replies. Thanks for your patience. 

                              • 12. Re: Getting field value from one layout and putting it in the same filed in another layout
                                jetmaster

                                re: refresh window that does not work; the ID changes but not the selected value in the list which remains the original despite the new vendor being added to the list. I need a drink! LOL Of pepsi of course!

                                • 13. Re: Getting field value from one layout and putting it in the same filed in another layout
                                  jetmaster

                                  OK I tried this:using _kf_vendor ID from equipment not vendor

                                  set variable [$companyID; value:equipment:__kfVendorID]

                                  go to layout ["service detail" (Servicing)]

                                  set field [servicing::_kf_vendorID; $companyID]

                                  and I related _kf_vendorID in both equipment and servicing....but nothing is happening...

                                  Can you related two FOREIGN KEYS?

                                  Going backwards here!

                                  • 14. Re: Getting field value from one layout and putting it in the same filed in another layout
                                    philmodjunk

                                    Yep, got it backwards

                                    set variable [$companyID; value:vendors::__kpVendorID]
                                    go to layout ["service detail" (Servicing)]
                                    Go to record/page [last]
                                    set field [Equipment::_kf_vendorID; $companyID]

                                    I'm not at all convinced that this is a good way to set up your relationships, but it should enable the script to update the vendor listed on your services layout.

                                    1 2 Previous Next