3 Replies Latest reply on Aug 25, 2014 9:33 AM by philmodjunk

    Creating a custom dialog box for a different table



      Creating a custom dialog box for a different table


           Ok I am trying to create a custom dialog box that inputs a new record in a differnt table than the one I am in. I want to do this without leaving the current layout location I am in

           So  this is what I have

           I am in Layout "LAYFireInspection" . Which is showing Table "Fireinspection" 

           I am in a tab within that layout that shows a portal to table "FireInspectionLineitems"

           I need the custom dialog box to create a new record in a Table Called "Defiency" and then be able to input 3 fields into the new record as well as add three varriables into three different fields also in the New Record created in the "Defiency" Table

           While doing this I do not want to loose my spot I am at in the Layout I have created

           I know how to do everything with the custom dialog box its the creating a new record in the "defiency" table without leaving my current location I cant seem to figure out.

        • 1. Re: Creating a custom dialog box for a different table

               I am assuming that you have a primary key field for FireInspections named __pkFireInspectionID. I am further assuming that you have a relationship linking FireInspections to Deficiency by this primary key value.

               The typical solution:

               Use Name box in the Inspector to assign an object name to this panel in your tab control. We'll call it "Inspections" for this example

               Then this script:

               Freeze Window
               Set Variable [$ID ; value::FireInspection::__pkFireInspectionID ]
               Got to layout ["Deficiency" ( Deficiency ) ]
               New Record/Request
               Set Field [Deficiency::_fkFireInspectionID ; $ID]
               Set Field [Deficiency::Field1 ; Globals::gField1]
               Set Field [Deficiency::Field2 ; Globals::gField2]
               Set Field [Deficiency::Field3 ; Globals::gField3]
               Go to layout [original layout]
               Go to Object ["Inspections"]

               The last step returns you to the same panel in the tab control where you started--creating the illusion that your script never changed layouts. The three "globals" fields here would be three global fields that you specify for the input fields in your custom dialog.

               This first method is easier to understand, but the change of layouts will cause portals to scroll back to row 1 and can trip any number of script triggers that might be set on either of the two layouts.

               Here's less commonly known approach:

               Go to Manage | Database | Fields and add a number field, _fkCreate to Deficiency. Add a calculation field named constOne to Fireinspection. Define it with the number 1 as the only term so that this field always has the value 1. Switch over to Relationships and make a new Tutorial: What are Table Occurrences? of Deficiency. Name it Deficiency|Add. Link it to FireInspection like this:

               FireInspection::constOne = Deficiency|Add::_fkCreate

               Enable "Allow creation of records via this..." for Deficiency|Add in this relationship.

               Now this script can be used:
               Set Field [Deficiency|Add::_fkFireInspectionID ; FireInspection::__pkFireInspectionID ]
               Set Field [Deficiency|Add::Field1 ; Globals::gField1]
               Set Field [Deficiency|Add::Field2 ; Globals::gField2]
               Set Field [Deficiency|Add::Field3 ; Globals::gField3]
               Set Field [Deficiency|Add::_fkCreate ; ""]

               This last option has something of a "smoke and mirrors" look to it for new developers, but exploits some lesser known details of how a "allow creation..." enabled relationship works. Set field [ RelatedTable::Field ; some value] will create a new related record just like adding data into a portal to the same table in the "add row" of that portal, but only if there is no related record. Thus the last set field step is used to clear the _fkCreate field in order to break the link to this new record, clearing the way for this script to be able to create another new record via the same relationship.

          • 2. Re: Creating a custom dialog box for a different table

                 Ok I see exactly what you are trying to do with the second option and it truly looks like it would work but it doesn't and I think I know why.  I see that the two tabels are related through the new fields constone and FK Create and by trying to set a field in the table because there is no record int the Defiency|add table that has a FK Create as 1 it then creates a new record and sets that field then at the end of the script you set the FK Create to "" so there is no longer a 1 in it which was created when it added the new record because they are linked through that number.  However whenever I run the script it runs the diologue box in it as well and its not creating a new record its kinda useing the last one

                 This is what I believe is happening the script is running in totality before the inputs are inserted via the Diologe Box.  So I need a way to pause the script while the diologe box is open and continue after the record is commited "ok" and if the "cancel" is selected it deletes that new record it just created

            • 3. Re: Creating a custom dialog box for a different table

                   Exactly correct. I assumed that you knew to put a show custom dialog with input fields at the start of either of these scripted examples. Show Custom Dialog both displays a dialog with the needed input field and pauses the script until the user clicks a button in the dialog. Get ( LastMessageChoice) can then be used in an If step to detect which button was clicked. As I review my previous post, I can see that I did not make that assumption at all clear in the post so apologies for that.

                   Show Custom Dialog ["Please enter a value..." ]
                   If [ Get ( LastMessageChoice ) = 1 //OK was clicked ]
                      Set Field [Deficiency|Add::_fkFireInspectionID ; FireInspection::__pkFireInspectionID ]
                       Set Field [Deficiency|Add::Field1 ; Globals::gField1]
                       Set Field [Deficiency|Add::Field2 ; Globals::gField2]
                       Set Field [Deficiency|Add::Field3 ; Globals::gField3]
                       Set Field [Deficiency|Add::_fkCreate ; ""]
                   End IF

              Caulkins Consulting, Home of Adventures In FileMaking