3 Replies Latest reply on Jul 31, 2014 11:11 PM by lowededwookie

    Creating records with scripts

    lowededwookie

      Title

      Creating records with scripts

      Post

           I'm having a bit of an issue. I've been trawling through some forum posts here for an answer to what I'm trying to do and have worked it out. Kudos FMP forums. But I've struck an issue.

           So I have a script for "New Job Updates" that looks like this:

           

                Set Variable [$Update; Value:Job_Updates::Date]
                Go to Object [Object Name: "JobUpdate"]
                Go to Portal Row [Select; Last]
                Set Field [Job_Updates::Date; $Update]
                Perform Script ["Job Update"]

           The second script called "Job Update" I have opens a window and allows me to edit that record. It looks like this:

           

                Set Variable [$JobUpdate; Value:Job_Details::ID Job Updates]
                Go to Related Record [Show only related records; From table: "Job_Updates"; Using layout: "Job_Updates" (Job_Updates); New window]
                Show/Hide Toolbars [Hide]

           This works perfectly except for two things:

             
      1.           One of the fields in the Job Update record is a date field. If I create a new record in this through the Job_Updates layout the Date field is automatically filled with the current date. This is desired behaviour. This however does NOT happen when I use the script to create the record even though the actual field is set to automatically enter the date on creation.
      2.      
      3.           When the second script is run it seems that I can't edit any data because the main window is "editing" the record. How do I get the main window to not "edit" the record so that I can edit the record from the window triggered by the script. Currently I have to click onto the main window anywhere outside the Job Update window then go back into the job update window to edit. NOT desirable behaviour.

           Any ideas what's going on?

           Thanks folks.

        • 1. Re: Creating records with scripts
          lowededwookie

               Ok I've solved issue 1 by using the following command:

               

                    Insert Current Date [Select; Job_Updates::Date]

               This only leaves issue 2 to sort out. How do I prevent this happening:

                

          • 2. Re: Creating records with scripts
            philmodjunk

                 Do in your script what you are doing manually. Clicking a blank area of the layout commits records and closes the record--allowing you to open it for editing in the new window. Have your script do a commit records while the first window is selected. (But becareful of when you commit records, make sure you capture the needed values from the last portal row record before committing records as this will remove the focus on the last portal row.

            • 3. Re: Creating records with scripts
              lowededwookie

                   I had a feeling that was the case but how do I capture the values?

                   If I commit the record in the "New Job Updates" script when it goes to run the "Job Updates" script it doesn't bring up the record I've just created.