October 11, 201213 yr I have a value list. Once the enduser makes a selection from the value list I would like to trigger a script where the user has three choices, to "Apply Primary" (which runs an apply primary script); to Apply Additional (which runs a applyAdditional script); or to cancel. What would such a script look like? I believe it would be "On Object Save" trigger.
October 11, 201213 yr The OnObjectModify trigger would be another viable choice, and the one I would personally prefer for mostly arbitrary reasons. I would start with something along these lines: If [not TriggersAreActive // Don't act if triggers are disabled: http://filemakerstandards.org/display/bp/Suppressible+Triggered+Scripts] Exit Script [] End If # Any opening steps common to all commands go here If [Get ( ActiveFieldContents ) = "Apply Primary"] # Apply Primary Else If [Get ( ActiveFieldContents ) = "Apply Additional"] # Apply Additional Else If [Get ( ActiveFieldContents ) = "Cancel"] # Cancel Else # Handle unknown/unexpected value End If # Any closing steps common to all commands go here I'm using Get ( ActiveFieldContents ) to figure out what the user selected, but you could also have the field pass itself as a parameter to the script in the trigger definition. In a production system, I might compare the field contents to the values in the same value list as used for the pop-up menu rather than comparing to literal text values so I could change the wording in the value list without needing to edit the script (or needing to remember to edit the script when I make that change 6 months from now). Assuming a ValuePosition custom function, the test would be something like: If [ValuePosition ( ValueListItems ( "" ; "Value List Name" ) ; Get ( ActiveFieldContents ) ) = 1]
October 11, 201213 yr Author I'm so sorry. I didn't explain myself well enough. Although, what you've suggested above helps me with another question I was going to place. In this current scenario... it doesn't matter what they pick from the value list (I really should have pointed that out--again, I do apologize). What's significant is that they had assigned a value to the field and now I want to provide them with a choice. Once they pick from the value list (any value), I then want them to identify what to do, "apply primary script", "apply additional script", or cancel. Something like... (I know this is wrong... just trying to move the conversion forward...) If [not TriggersAreActive // Don't act if triggers are disabled: http://filemakerstandards.org/display/bp/Suppressible+Triggered+Scripts] Exit Script [] (I like this safeguard... just curious under what circumstances would triggers be disabled?) End If... # Any opening steps common to all commands go here After they pick from the value list (whatever the value they pick) I want to Show Custom Dialog [title] "What do you wish to do? Apply as primary household, additional household or cancel?"; Table1::???then what? If they pick "Apply Primary" I want to run the apply primary script # Apply Primary Else If "Apply Additional" I want to run the apply additional script # Apply Additional Else If "Cancel" # Cancel Else (between this Else statement and the following End If... would say Halt script be appropriate? so if they do anything else they will simply exist the script?) # Handle unknown/unexpected value End If # Any closing steps common to all commands go here
October 22, 201213 yr When you define a custom dialog, you define up to 3 buttons for the users to click on the dialog. Your script can see what the user selected with the Get ( LastMessageChoice ) function: Show Custom Dialog [...] If [Get ( LastMessageChoice ) = 1 // "Apply Primary"] # Apply Primary Else If [Get ( LastMessageChoice ) = 2 // "Apply Additional"] # Apply Additional Else # Cancel End If One example of when you might want to disable scripts is if you have a script that goes to another layout to create a record, then returns to the first layout; it's a waste of processing time to sort the the records in the target layout via its OnLayoutEnter trigger. More complicated scenarios can arise where scripts trigger unanticipated chains of events that circularly trigger themselves again. Suppressing triggers prevents any unintended loops from arising.
Create an account or sign in to comment