7 Replies Latest reply on Mar 16, 2012 7:25 PM by philmodjunk

    Set a value in a pop up menu field

    JCPython

      Title

      Set a value in a pop up menu field

      Post

      i have a pop-up menu field of customers in my invoice screen, i want to add a button on the customer records screen that says " Create invoice" and i want to script it to go to the invoice layout and input the customers name of the customer record i was on into the customers name on the invoice field bill to customers.

       

      i tried using set field script step and insert calculated text, but i got no results at all, i notice that the script step "set field" only seems to work for me certain times. im using filemaker pro advanced 11 if that makes any difference.

        • 1. Re: Set a value in a pop up menu field
          philmodjunk

          Knowing how your tables are related and whether this is a database system of your own design or the starter solution would help.

          If you have this relationship:

          Customers---<Invoices

          Customers::CustomerID = Invoices::CustomerID

          Then this script will work:

          Set variable [$CustID ; value: Customers::CustomerID ]
          Go to layout [Invoices]
          new Record/Request
          Set field [Invoices::CustomerID ; $CustID]

          To show the customer name on your invoices layout, you'd add the customer name field or fields from Customer to your invoices layout.

          • 2. Re: Set a value in a pop up menu field
            JCPython

            its a starter solution, i added a photo of the relationships setup.

            • 3. Re: Set a value in a pop up menu field
              philmodjunk

              What I described is the script you want to use, but now I can be mroe specific:

              Set variable [$CustID ; value: Customers::CustomerID ]
              Go to layout [Invoices]
              new Record/Request
              Set field [Invoices::Ship To Customer ID ; $CustID]
              Set field [Invoices::Bill To Customer ID ; $CustID]

              Note the two fields for customer ID, you can have your script put a customer ID value in one or both of them.

              Unless you've changed the layout design. You won't need to add customer name fields to the layout as the pop up menus are formatted to display the customer name.

              • 4. Re: Set a value in a pop up menu field
                JCPython

                Works great! this is very interesting im gonna do some looking up more on variables, never really used them and ont really undrstand how it made what i want to do work, but it works :)

                • 5. Re: Set a value in a pop up menu field
                  philmodjunk

                  The results of many script steps depend on the layout and record on that layout that is current at the time that script step is executed.

                  Set Field is one of those script steps. Any references to a field from a related table are controlled by the relationship linking the layout's table occurrence to the table occurrence to which the set field step refers. (Table occurrences are the "boxes" found on the relationships tab in Manage | database.)

                  Thus this script will fail:

                  new Record/request
                  Set field [Invoices::Ship To Customer ID ; Customers::CustomerID]

                  for the very reason that there isn't any relationship between invoices and customers that's valid. Not only does your relationship graph not have such a relationship, (it links to occurrences of customers that have other names: Invoice Billing Customer and Invoice Shipping Customer), there's no way to link to a customer record until after a value is entered into a customer ID field in Invoices.

                  My script avoids that problem by using a variable. Think of $CustID as a bucket. Set Variable takes the value of Customer ID in the current customer record and sticks it in the bucket, it then walks over to the invoices layout, makes a new blank record and dumps the value from that bucket into the customer ID field in Invoices.

                  • 6. Re: Set a value in a pop up menu field
                    JCPython

                    That makes perfect sense, and i see how it can be very usefull using a variable, so if i understand correctly, set field is to be used when a relationship is established between the tables if the target is in one table and the value is in the other, and variable is to be used when no relationship is established, please correct me if i am wrong.

                    • 7. Re: Set a value in a pop up menu field
                      philmodjunk

                      That's one use for variable. There are many other uses for it as well.