Andrew, can you explain a little more what you are trying to accomplish?
hi Daniel, basically want to avoid duplicates in a line items portal in the layout client foundsets. Sometimes a user might add over 1000 contact entries to a list so it's good to avoid accidentally adding the same person twice..
I See this being a dialog box saying contact already assigned.
Thanks Andrew. That's helpful. One approach is to use an OnObjectSave on the field the user selects ( e.g. the Customer field). The script might look like this:
$customerID = CUSTOMER::ID
$duplicateCustomer = PatternCount ( PORTAL_TO::customerID ) > 1
If [ $duplicateCustomer = True
Show Custom Dialog...
Revert Record [no dialog]
First of all, the PatternCount should be
PatternCount ( List ( PORTAL_TO::customerID ) ; $customerID )
Secondly, this will work for UUID but it will not work if your primary key is a serial number. For example, if customerID=111 is already in the portal and a user tries to add customerID=111, you'll get a false positive.
A better approach may be to use the FilterValues () function which should work with both UUID as well as serial numbers:
FilterValues ( List ( PORTAL_TO::customerID ) ; $customerID )
You can make this a boolean by adding isEmpty:
isEmpty FilterValues ( List ( PORTAL_TO::customerID ) ; $customerID )
Hope that helps.
Thanks Daniel, perhaps filtering would be the best way to go on the popover - when a contact is added to the line items portal they should disappear from the popover to contacts.
However i have this filter on that portal already. This enables a search ability.
If ( IsEmpty (CLIENTS FOUNDSET::Search) ; 1 ; PatternCount (CLIENTS_FOUNDSET_POPOVER::c_name for foundset Portal & CLIENTS_FOUNDSET_POPOVER::Contact Type ; CLIENTS FOUNDSET::Search) > 0 )
What would be a way to remove the contact from the popover when added to the line items portal?
Can you attach a couple of screen shots of the layout in browse mode? One with the popover closed and the other with it open?
I presume the attendee's name in the Add Contact popover is a button. When the user clicks that button, the script can search for duplicate records as I mentioned in #4 above:
SetVariable $attending [ Not IsEmpty ( FilterValues ( List ( PORTAL_TO::customerID ) ; $customerID ) ) ]
If [ $attending = True ]
Cancel process, revert record, and show custom dialog to inform user
Thanks! Is this correct?
can still add names twice so must be something incorrect somewhere along the line... thanks
sorry noticed i missed the last bit.. how do you "revert record" and do the last bits?
Andrew, do you have FileMaker Pro Advanced? If so, step through the script and verify that $attending = 1 (1 and True are the same; I usually script $variable = True rather than $variable = 1 because I think it is easier to read).
Also, in the Data View try the calculation FilterValues (List...
and verify that is working.