9 Replies Latest reply on May 2, 2011 12:23 PM by philmodjunk

    Trouble with script that seems like it should be easier

    MatthewMackay

      Title

      Trouble with script that seems like it should be easier

      Post

      I'm trying to create a workaround for the issue with show custom dialogue with FM Go 1.2.

      I've created a layout to act as the custom dialogue box but adapting my script to encompass this doesn't work, I can't figure it out at all.

      The script is used to add data to a field that will add values to an existing value list wchich is displayed as a check box set.

      The user will be on a specific item's record which has a check box set on it. If the item they're looking for is not in the checkbox set, they press a button which runs the script to add to that value list.

      This goes to a layout, still showing records from the same table, creates a new non related record where they can define a new value which goes in to the check box set.

      This part is fine, it's getting back to the record that they started from that's the problem. Because the record they were working on might not be the last one that was created, I'm guessing I'd have to use a calculation but have no idea where to begin.

      If more info is required, let me know.

      Cheers

        • 1. Re: Trouble with script that seems like it should be easier
          philmodjunk

          I gather that you are just changing layouts and not using New Window to open up a second window for the data entry? With New Window, you can can open the window, the user can enter data, click a button to close the window and you are right back on the same layout, same record.

          Is the new record being created in the same table as the table of your layout where the button is clicked? If not, you should be able just to return to the same layout and all will be where and as you left it. If it's the same table and you don't want to open a window, there are two work arounds that you can use:

          1) Open Manage | Database | Relationships, find the Table Occurrence "box" that your current layout refers to. Click the button with two green plus signs to make a copy of it. Now base your second layout on this table occurrence. Since the two layouts refer to different table occurrences of the same data source table, you can add a new record, perform finds, sorts etc on the second layout without affecting the current record, found set, and sort order of the first layout.

          2) Use Set Variable to store the primary key (auto-entered serial number field) of your current record. After doing the add record and returning, perform a find that uses the value in the variable as your criteria to return to the record you were on when you started. Keep in mind that if this was one record of a found set of several records, this now leaves you with a found set of just the 1 record that was current when you first clicked the button.

          • 2. Re: Trouble with script that seems like it should be easier
            MatthewMackay

            I've recently posted regarding using pop up windows on FM Go.

            Can the pop up be displayed above the current layout? Locked so the user has no control over the window?

            Cheers

            • 3. Re: Trouble with script that seems like it should be easier
              MatthewMackay

              Sorry, locked so the user has no control over the window apart from the fields and buttons?

              • 4. Re: Trouble with script that seems like it should be easier
                philmodjunk

                Yes. You can make the new window simulate modal behavior with this script fragment:

                Allow User Abort [off]
                Loop
                   Pause/Resume Script [Indefinitely]
                End Loop

                This is an infinite loop that you include at the end of the script that opens the new window. You then use buttons and/or scripts that use Halt Script to terminate the infinite loop when the user finishes with the window and clicks a button to close the window and return to the original window.

                Just be careful to test your script with the Allow User Abort step removed or disabled first. A scripting mistake on your part could trap you with an infinite loop that can only be intrerrupted by using the debugger to halt the script (If you have FileMaker Advanced) or by force quitting FileMaker.

                You can see scripted examples of this technique in my Known Bugs List Database. The Find, Modify Find, New and Edit buttons all run scripts that open up new windows, while minimizing Windows Platform window resize glitches and adjusting sizes so that the new windows are the correct size on a windows platform even if the "enlarge window contents..." preference has been selected. I also use a custom menu so that close window in the file menu works to close the window and this makes the close button in the corner of the new window functional. (Without the custom menu, or in a runtime system, you have to use a button on the layout to close the window.)

                • 5. Re: Trouble with script that seems like it should be easier
                  MatthewMackay

                  Thanks, I'll have a look at this tonight and get back to you if any further issues.

                  Cheers

                  • 6. Re: Trouble with script that seems like it should be easier
                    MatthewMackay

                    The pop up window doesn't work on the ipad as it opens a whole new window, not producing the pop up desired.

                    Still having problems with the script though.

                    You mentioned above;

                    "Use Set Variable to store the primary key (auto-entered serial number field) of your current record. After doing the add record and returning, perform a find that uses the value in the variable as your criteria to return to the record you were on when you started. Keep in mind that if this was one record of a found set of several records, this now leaves you with a found set of just the 1 record that was current when you first clicked the button."

                    I have a button that goes to a layout, a new record is created then the use enters in data in to a couple of fields. On this layout, there are 2 buttons, "Ok" and "Cancel".

                    1 script for adding the new item, 1 script for the cancel button and the "Ok" script just needs to go back to the previous layout/record.

                    If the 1st script sets the variable, am I right in saying there's no way the the scripts for "Ok" or "Cancel" can use this variable?

                    Still can't get my head around why it's proving so difficult.

                    • 7. Re: Trouble with script that seems like it should be easier
                      philmodjunk

                      If you name your variable with $$ at the beginning, it becomes a global variable and it's value will remain when the script that assigned it a value exits. Thus, the other scripts can then access this value when they execute.

                      New Window opens up a new window in FileMaker Pro as well. That's how it's supposted to work. In FileMaker Pro, the new window script step allows you to specify a smaller window size and a postion that centers it on your screen so that it "floats" in front of the original window and you can use it as a dialog box for entering data.

                      Unlike Show Custom dialog, this window uses a regular FileMaker layout so you can use value lists, have more than 3 buttons, all buttons commit the input data not just button 1...

                      Doesn't it do that in the iPad in GO as well?

                      • 8. Re: Trouble with script that seems like it should be easier
                        MatthewMackay

                        Sweet relief!!

                        Global variable works perfectly, I've not really worked with them before, will have to look in to them.

                        The new window script worked fine on FM Pro as you said.

                        Even with the new window size being smaller than the current window, on the iPad, it just open a new window that fills the screen regardless of what size the script specifies.

                        Not great with the current custom dialogue bug, going to a seperate layout is working quite well within my solution, cheers for your help.

                        • 9. Re: Trouble with script that seems like it should be easier
                          philmodjunk

                          Even with the new window size being smaller than the current window, on the iPad, it just open a new window that fills the screen regardless of what size the script specifies.

                          Please go to Report an Issue (See tab at top of screen) and report this. This is not expected behavior for Filemaker GO and I have not seen it reported thus far as an issue.

                          I'd report it myself, but since I don't own an iPad, I can't respond to any follow up questions the tech folks at FileMaker might ask...