5 Replies Latest reply on Jan 9, 2015 6:31 AM by philmodjunk

    Popover for contact data entry against related field

    Stu412

      Title

      Popover for contact data entry against related field

      Post

      Hi there

      I've got a couple of choices of methodd to add contacts to customers, I can use a portal which works very well but looks a little ugly, or I'd rather use a popover.

      The latter, I've got a script which passes the entered details to global fields and from there, to the related contacts table.  This is working fine.

      The problem which crops up is that when I enter a new contact via the popover method, it's creating a new blank record based on the parent (customer) layout, which clearly I don't want.  This is some cases has the same ID as an existing customer which is nuts.  My customer table is auto number and serial and the relationship between that and contacts is such that no records should be created there.

      When I use the portal method, based on this existing relationship, everything works as I want it - but it's ugly!

      Here's the script I'm working with at the moment attached, hope you can read it as I cannot copy/paste from FM for some reason.

      The Clean up Contact Popover script just blanks out the global fields in the popover for use next time.

      Edit: I've taken a second look at this and believe the New Record/Request step is creating the new parent records. If I take this out, that's one problem solved.  However, the next issue is that the last entered contact record already exists in the new popup and simply gets over written by new data. 

      Any help appreciated, thanks

      Capture2.PNG

        • 1. Re: Popover for contact data entry against related field
          philmodjunk

          What is your Context when this script executes? From your post, referring to a portal and the mention of a "related field" in your post's title both imply that you have at least two tables linked in a relationship.

          At the time this script executes are you on a layout based on Contacts or a layout based on some other table such as a table of invoices?

          • 2. Re: Popover for contact data entry against related field
            Stu412

            Hi Phil

            That's correct yes, I've a second table.  The context is that each customer can have several contacts (their own staff members if you will).  The tables involved are Customers and Contacts.

            When I execute the script, I'm on the Customers layout (which to be fair may be the issue) BUT I was kind of hoping, from a user experience point of view, that from within the Customers layout I could use a popover to add related data, such as their own staff members, as opposed to transferring the user to another separate view.

            Thanks

             

            • 3. Re: Popover for contact data entry against related field
              philmodjunk

              When I execute the script, I'm on the Customers layout

              Which means that  the new record step in the script that you posted is creating a new customer record and not a new contact record.

              each customer can have several contacts

              By what means are you linking a single customer to multiple contacts? Can the same contact be linked to more than one customer?

              I was kind of hoping, from a user experience point of view, that from within the Customers layout I could use a popover to add related data, such as their own staff members, as opposed to transferring the user to another separate view.

              No need for the user to change views. The script can change views, add the new record and then change back. The user need never see the view change.

              If contact records are only linked to a single customer but customers can link to many contacts, you should have this relationship:

              Customers::__pkCustomerID = Contacts::_fkCustomerID (though you may name things differently)

              A script performed from a layout based on Customers might add a new Contact record like this:

              Set Variable [$CustID ; value: Customers::__pkCustomerID ]
              Go to Layout ["Contacts" (Contacts)]
              New Record/Request
              Set FIeld [Contacts::_fkCustomerID ; $CustID ]
              #Put your set field steps to transfer data from the global fields to corresponding fields in Contacts here

              Go to Layout [origional layout ]

              PS. this script will, as a side affect close any open popover. If you want to keep the popover open when this script is performed, give the popover an object name via the name box in the inspector and include a go to object step that specifies that object name as the final step of the above script.

              Second note, a change in layouts by this type of script can trip all kinds of script triggers. There are ways to use a global variable to keep those scripts from doing anything that might interfere with the execution of this script.

              • 4. Re: Popover for contact data entry against related field
                Stu412

                Phil

                Genius!

                I've added a couple of rows based on the script as I've got a many to many relationship between customers and their contacts, but it was pretty straightforward given the content of the original script.

                I hope to be able to use that logic elsewhere as well, so thanks for your help and patience!

                • 5. Re: Popover for contact data entry against related field
                  philmodjunk

                  Here's a bit more that you may find useful:

                  The key issue that this type of script can "trip" is that nearly every script trigger on two different layouts might get tripped when the script changes to a different layout and then changes back. If you make a habit of writing script trigger performed scripts with this type of code:

                  If [ Not $$TriggersOff ]
                    Put rest of script here
                  End If

                  You can then "disable" script triggers by using:

                  Set Variable [$$TriggersOff ; value: True ]
                  Before changing layouts and then use
                  Set Variable [$$TriggersOff ; Value: False ]
                  To re-enable them before the script exits or halts.