1 Reply Latest reply on Dec 9, 2013 2:16 PM by philmodjunk

    SetField and Loop

    layotte

      Title

      SetField and Loop

      Post

           Currently I have a script which gets an expectation id from a table, sets a global field and brings the information back to an activity table.  The users have been using the file this way but have asked to be able to select more than 1 expectation and bring them back to the activity table.  In the expectation table there are checkboxes with each expectation.  As soon as the checkbox is marked a script trigger runs the script below. I am not sure how to proceed to allow users to select more than one expectation.  I would have to take away the script trigger and add a back button but not sure if I need to do a find for all the "X" or set a number of global fields to include all the "X".  Any help is appreciated.

           Here is the script

           If [EXPECTATIONS::select_expectation = "X"]
                SetField [EXPECTATIONS::g_ExpectationID; EXPECTATIONS::__kp_expectations_id]
           Else
                SetField [EXPECTATIONS::_g_ExpectationID; ""]
           Replace Field Contents [No dialog; EXPECTATIONS::select_expectation; ""]
           Go to Layout ["ACTIVITIES" (ACTIVITIES)]
           Go to Object [Object Name: "Tab Expectations"]
           Go to Field [EXPECTATIONS::__kp_expectations_id]
           Go to Portal Row [Last]
           SetField [Activity_Expectation::_kf_ExpectationID; EXPECTATIONS::_g_ExpectationID]
           SetField [ACTIVITIES::Add_Expectation_fromActivities; "Choose Subject"]
            

        • 1. Re: SetField and Loop
          philmodjunk

               You also have an additional problem if this is or will be a database that is hosted over a network and more than one user may be selecting this at the same time. Their choices will interfere with each other and the Replace Field Contents step may clear a user's selection before they want it to be cleared and edit locks on records can keep selected records from being cleared when they should be.

               I'd also use a global variable instead of a global field unless this is a very old version of FileMaker that you are using.

               What you can do, is update a global variable (this works with a global field also) such that it becomes a list of selected expectations separated by return characters. Selecting a control set up to look and act like a check box (but isn't) to select an object adds it to the list. Clicking it again to clear the selection deletes the item from the list in the global variable.

               Your user can then click to select multiple items without any interference from other users and they can click a button named "done" or somthing to start a script to take them back to the other layout where the script can loop through the values in the global variable's list.

               Here's a sample Select/Deselect script example:

               If [ IsEmpty ( FilterValues ( $$ExpectList ; EXPECTATIONS::__kp_expectations_id ) ) // item not selected, select it ]
                  Set Variable [ $$ExpectList ; List ( $$ExpectList ; EXPECTATIONS::__kp_expectations_id ) ]
               Else
                  #Item is already selected, clear it
                  Set Field [$$ExpectList ; ¶ & $$ExpectList & ¶ ]
                  Set Field [$$ExpectList ; Substitute ( $$ExpectList ; ¶ & EXPECTATIONS::__kp_expectations_id & ¶ ; ¶ ) ]
                  Set Field [$$ExpectList ; Middle ( $$ExpectList ; 2 ; Length ( $$ExpectList ) - 2 ) // strips off leading and trailing returns ]
               End IF

               You can then set up a rectangle object and Layout text with a conditional formatting as both a button to perform this script and with conditional formatting that hides/reveals the "x" or other layout text used to show that the user has selected that item.