The menu gets its value list from a field in another table.
When I click a value it populates the field as it should.
If i click a new value it repopulates the field with the new value.
What i would like it to do is add the new value to what is already populated. Also, i wuld like filemaker to recognize if the numbers are in sequence or not.for example:
First, let's look at how selecting a value from the drop down can add/remove it from a return separated list of values. Once you can do that, the script can loop through the values, building ranges for adjacent values.
If [ IsEmpty ( FilterValues ( YourTable::SelectedValues ; YourTable::DropDownField ) ) // Value is not in list ]
#Add the value to the list in ascending order
Loop
Set Variable [$K ; value: $K + 1 ]
Exit Loop If [$K > ValueCount ( YourTable::SelectedValues ) ]
Exit Loop If [GetValue ( YourTable::SelectedValues ; $K ) > YourTable::DropDownField ]
End Loop
Set Field [ YourTable::SelectedValues ;
List ( LeftValues ( YourTable::SelectedValues ; $K - 1 ) ;
YourTable::DropDownField ;
RightValues ( YourTable::SelectedValues ; ValueCount ( YourTable::SelectedValues ) - $K + 1 ) ) ]
Else
#Remove the item from the list
SetVariable [$TheList ; Value: Substitute ( ¶ & YourTable::SelectedValues & ¶ ; ¶ & YourTable::DropdownField & ¶ ; ¶ ) ]
Set Field [ YourTable::SelectedValues ; Middle ( $TheList ; 2 ; Length ( $TheList ) - 2 // strips out leading and trailing returns ]
End If
Test and make sure you can get this to work. It's not the final answer, but if it works, SelectedValues should contain a return separated list of numbers sorted in ascending order where on ONObjectSave script trigger performing the above script correctly adds/deletes values from this list.
NEXT
I realize that is what you want, We've just set up a prelminary list of numbers that can be converted into what you want.
If you just wanted a comma between each selected value, we could use the substitute function to turn the returns into commas, but condensing adjacent values into ranges with a hyphen will take something that can loop through this list--either a custom function created in FileMaker Advanced or via a script that loops through these values.
I had to test this one out in a test file.
YourTable::FinalList is the field that holds the list where adjacent values have been condensed into ranges.
Loop
Set Variable [ $J; Value:$J + 1 ]
Exit Loop If [ $J > ValueCount (YourTable::SelectedValues ) ]
Set Variable [ $Value; Value:GetValue ( YourTable::SelectedValues ; $J ) ]
Set Variable [ $TheList; Value:List ( $TheList ; $Value ) ]
If [ $Value + 1 = GetValue ( YourTable::SelectedValues ; $J + 1 ) // Adjacent value ]
Loop
Set Variable [ $J; Value:$J + 1 ]
Set Variable [ $Value; Value:GetValue ( YourTable::SelectedValues ; $J ) ]
Exit Loop If [ $Value + 1 ≠ GetValue ( YourTable::SelectedValues ; $J + 1 ) // NonAdjacent value ]
End Loop
Set Variable [ $TheList; Value:$TheList & "-" & $Value ]
End If
End Loop
Set Field [ YourTable::FinalList; Substitute ( $TheList ; ¶ ; ", " ) ]
Your new post is loading...