March 7, 201411 yr Hi, I am trying to write a script that when a user selects a value from a predefined value list, if that value has already been used it Undoes/Removes that value. This script applies to a portal by the way. It works in that if I select say the value '2014' then in the next record I select the same value '2014' it removes it. But if I select '2014', then in the next record '2015', then in the next record '2014' it doesn't remove it. It's as if it's only checking the previous record for a duplicate and not all the records yet i'm telling it to loop through them all to check for duplicates. Here is my script: - Go to Portal Row [Select; First] Set Variable [$UniqueField; Value:Client Account Deposits For Accounts::Date] Go to Portal Row [Select; Next] Loop Exit Loop If [Get(FoundCount)=0] If [Client Account Deposits For Accounts::Date = $UniqueField] Undo/Redo [Undo] Exit Loop If [Get(FoundCount)≠0] Show Custom Dialog["Message Notice"; "Year already exists, please select alternative year"] Else Set Variable [$UniqueField; Value:Client Account Deposits For Accounts::Date] Go to Portal Row [Select; Next; Exit after last] End If End Loop I am aware of the 'unique value' setting for a field but don't wish to use it in this scenario. Any help with my script would be greatly appreciated. Cheers Steve
March 7, 201411 yr What about creating a temporary new record entry area, instead of entering it directly into the portal? Create a global field where they enter the value (could be a drop-down or basic edit box); then you have a script on a trigger that first does a search in the existing records for that value; if found count = 0 then you can create a new record. If it is > 0, then you don't create a record. set $var = global_entry_field go to layout "Utility" [target_table] enter find mode set field "Date" = $var perform find if (get(foundcount) = 0 ) create record else show custom dialog: "That value already exists." end if There are a number of other ways to find out if records exist that match a certain value; doing a Find is just one of them. -- J
March 7, 201411 yr I don't understand your script that well (what's the role of Get(FoundCount)=0 in the loop?). In general, you can look at all values present in child records at once, using the List() function - so looping over a portal should not be necessary. You might also look into removing any previously used values from the value list - see: http://fmforums.com/forum/showpost.php?post/274656/ -- Note that none of these methods are designed to replace field-level validation completely.
March 7, 201411 yr Author Justin, thank your suggestion, i'm not sure it's really what i'm after but I will give it a try. Hope I don't sound too unappreciative. Consultant, I'm still learning myself how loops work and having looked at literally 100's of examples, as I understand, the Get(FoundCount)=0 is necessary if i'm entering a new record for the first time. Likewise [Get(FoundCount)≠0] I have found seems to be necessary because if I don't include it the script fails for some reason and an egg-timer appears on my screen of which I have to press escape to stop the script from running. Thank you both anyway, I will keep looking and trying different examples to learn more about how they work as sure it's just a matter of tweeking mine a little to get it to work. Steve
March 7, 201411 yr I am afraid you are working under several false assumptions here. Get (FoundCount) counts the records in the current found set. It has nothing to do with a portal. In the situation you describe, Get (FoundCount) will never be equal to 0. Regarding the egg-timer: if you don't include an exit condition in a loop, the loop will be endless. If your exit condition is Get (FoundCount)≠0, then the loop will exit, because - as I just said - this will always be true. You could just as well have used Exit Loop If [1]. Effectively, both conditions neutralize the loop statement, since the loop will never get to a second iteration. There are other things in your script that need untangling, but rather than discussing them, I recommend (again) you adopt a method that doesn't require looping over a portal.
Create an account or sign in to comment