1 2 Previous Next 18 Replies Latest reply on Jan 24, 2014 2:23 PM by keywords

    Add A New Record Script to Portal

    micheleclark

      Hi!

       

      Can you help me understand how to set my script of "New Record/Request" to add a new record specifically to a Portal as oppose to my main table?

       

      Thanks so much.

        • 1. Re: Add A New Record Script to Portal
          Mike_Mitchell

          Michele -

           

          There are a couple of ways to create a new record in a related table (which is what a portal reflects).

           

          1) If you set the relationship to allow the creation of related records, you can simply go to the last portal row (which will be empty) and use any number of script steps (such as Set Field, Insert, or Paste) to put data into the related fields. For example:

           

          Go to Portal Row [ Last ]

          Set Field [ relatedTable::field ; new data ]

          Set Field [ relatedTable::field2 ; new data ]

          Commit Records / Requests

           

          2) You can also create a related record by going to a layout that's based on that related table (which is called the "context"), then executing your New Record / Request step, then going back to the original context. For example:

           

          Go to Layout [ layout based on related table ]

          New Record / Request

          Set Field [ relatedTable::field ; new data ]

          Set Field [ relatedTable::field2 ; new data ]

          Go to Layout [ original layout ]

           

          HTH

           

          Mike

          2 of 2 people found this helpful
          • 2. Re: Add A New Record Script to Portal
            micheleclark

            Hi Mike,

             

            Thanks so much for your help.

             

            I've tried the calculations you provided and am having some difficulty still. First off, I am not sure how to get  ... ; new data ] at the end of my lines.

             

            Also, my portal is drawing from two different fields. Is there a special technique I should use to jump from one field to the next? As of now, when I enter in my second data entry field, which ends up being the first field of a second table, the information enters into every other record.

             

            I hope that makes sense

             

            Best, Michele

            • 3. Re: Add A New Record Script to Portal
              Mike_Mitchell

              Michele -

               

              The examples I gave you were script steps, created using the Manage Scripts dialog (Scripts > Manage Scripts). That's where you'll go to create your script.

               

              In order to insert the data you want into your new record (the part I have as "new data" above), you'll use the Calculation Dialog. To get there, you'll use the Set Field script step:

               

              setField.png

               

              When you insert that into your script, you'll use the "Calculated result" button to tell FileMaker what data to insert:

               

              setField.png

               

              I don't know what data you want to insert, but you would do that inside that dialog.

               

              To insert the data into a different field, you use the "Specify target field" button and tell FileMaker what field you want to use. You'll do this for each Set Field command. Each command would address a different field, depending on what data you want to insert.

               

              If I'm understanding what's going on correctly, I think you're probably sending the two Set Field commands to the same field in two different portal rows. You probably also have more than one Go to Portal Row command; you only need one. Just create a new script in the Manage Scripts dialog with the steps I have above, and it should be fine.

               

              Mike

              • 4. Re: Add A New Record Script to Portal
                micheleclark

                Hi Mike,

                 

                Thanks for following up.

                 

                I feel like I'm running in circles. I apologize.

                 

                I have set a new script to make sure everything is fresh, as my scripts either claim now they were deleted or are jumping to the wrong field.

                 

                I still do not see where "new data" can be applied, as all my fields are data punch ins thus I do not believe require for me to specify calculations.

                 

                The table and the portal do have a relationship table between them, does this affect it?

                Screen shot 2013-02-11 at 3.21.32 PM.png

                I am trying to get a fermentation_logs portal into my productions form.

                Screen shot 2013-02-11 at 3.24.28 PM.png

                 

                 

                My Script linked to Add Transaction looks like this

                 

                Screen shot 2013-02-11 at 3.21.48 PM.png

                 

                Do you see any clues?

                 

                Thanks,

                 

                Michele

                 

                PS Now every script I write "cannot be found or has been deleted" :/

                • 5. Re: Add A New Record Script to Portal
                  micheleclark

                  Hi Mike,

                   

                  I am beginning to think I do not even need a button, as the field appears and once I start filling it out a new record appears under it. Was that obvious? I was so stuck on having an add button.

                   

                  Does the following seem right?

                   

                  This was using this script in this form:  ((Do you see any issues here or any reasons why not to use the "Go to"?

                   

                  Screen shot 2013-02-11 at 3.41.37 PM.png

                  Screen shot 2013-02-11 at 3.41.42 PM.png

                   

                  Thanks for being awesome,

                   

                  Michele

                  • 6. Re: Add A New Record Script to Portal
                    Mike_Mitchell

                    If all you want to do is add a new record, then, no, you don't need a script. All you have to do - as you've discovered - is put your cursor in the last (empty) row of the portal and start typing. This will automatically create a new record.

                     

                    If your portal is not tall enough to show the blank row (and it won't be if there are enough records), then you can add a button that executes a script with the steps you have, only a slight modification:

                     

                    Go to Field [ item::serial_number ]

                    Go to Portal Row [ Last ] (don't choose "Select")

                     

                    This will place the cursor in the last row.

                     

                    Mike

                    • 7. Re: Add A New Record Script to Portal
                      Mike_Mitchell

                      Your Set Field steps are still missing the data - what you want FileMaker to set the field to. I know it's a little confusing to say you use the "Calculation Dialog" to insert a constant, but a constant is a form of calculation in the FileMaker world. (Example: "1" is a text constant you could type in the Calculation Dialog; it always evaluates to the text string, well, "1".)    :-)

                       

                      But if you just want to move to the field, then Set Field isn't what you want. That's for when you want to insert actual data into the field.

                       

                      As for why it's telling you, "This script cannot be found or has been deleted," it's probably because you never attached a script to the button. You do this by choosing "Perform Script", then clicking "Specify" in the Button Setup dialog:

                       

                      dialog.png

                       

                      If there's no script selected, FileMaker will give you that error. (You can get this dialog by double-clicking the button.)

                       

                      Let me know if you have further difficulties.

                       

                      Mike

                      • 8. Re: Add A New Record Script to Portal
                        millerb

                        Hi Mike,

                         

                        I'm having one of those days. I've set up just the sort of script you describe to create a new related record and set a field value. But I can't get that far because the script keeps stopping (exiting) as soon as I get to the New Record/Request step on the main table. I think I must be making some obvious mistake, but I can't see it. The Script Debugger only gets as far as "New Record/Request" then shows no more script steps. I can add the related record manually through a portal, so I believe the relationships are set up correctly. Here's the script, and the place where it stops:

                         

                        Go to Layout [ “Organization Contact - Detail” (ORGANIZATIONS) ]

                        New Record/Request

                         

                        ***This is as far as the script gets, then it just exits and leaves the cursor in the first field of the above layout. I set the data viewer to show the value of $OrgID (next step below), and it never shows a value.***

                         

                        Set Variable [ $OrgID; Value:ORGANIZATIONS::_ID ]

                        Go to Layout [ “ContactsJoin” (ContactsJoin) ]

                        New Record/Request

                        Set Field [ ContactsJoin::_OrgID ; $OrgID ]

                        Commit Records/Requests [ No dialog ]

                        Go to Related Record [ From table: “ORGANIZATIONS” ; Using layout: “Organization Contact - Detail” (ORGANIZATIONS) ]

                         

                        I checked the script triggers on the main layout and the only one is OnLayoutEnter (resize/refresh). No other script triggers that could be interfering. I also had problems today with a script to show my own custom dialog, and no beep, when Get(FoundCount) = 0, and that also didn't doing anything. I'm beginning to worry there's something wrong with FM13 or with my file. I'm a newbie, in-house staff at a nonprofit, so I could just be missing something obvious. Any idea what's going on?

                         

                        Thanks so much.

                        JB

                        • 9. Re: Add A New Record Script to Portal
                          Mike_Mitchell

                          JB -

                           

                          What error code does the debugger report when it attempts to execute the New Record / Request step?

                          • 10. Re: Add A New Record Script to Portal
                            millerb

                            There's no error. It simply creates the new record (in the parent layout as specified) and then happily stops there with the cursor blinking, like its work is done. It's as if the rest of the script doesn't exist (yes, I saved it!). The Script Debugger goes blank and no value appears for $OrgID in the Data Viewer.

                            • 11. Re: Add A New Record Script to Portal
                              Mike_Mitchell

                              Can you attach a copy of the file?

                              • 12. Re: Add A New Record Script to Portal
                                fitch

                                Your script is setting $OrgID to the value of the _ID field on the new record. Presumably, that field auto-enters a serial number. Perhaps it's set to generate the number on commit rather than on creation? Try adding a commit script step before the set $OrgID.

                                • 13. Re: Add A New Record Script to Portal
                                  fitch

                                  Is it possible you accidentally disabled those script steps?

                                  • 14. Re: Add A New Record Script to Portal
                                    millerb

                                    Good suggestions. No, I didn't disable any script steps. I tried adding a commit script step, but it didn't fix the problem. I've scaled down the copy to just the bit I'm struggling with and am trying to figure out how to ZIP it to send. One minute!

                                     

                                    Thanks!

                                    1 2 Previous Next