Greg58 Posted June 27, 2020 Posted June 27, 2020 I have a list of items in a category dropdown list. If a user clicks on the dropdown and the item they want is not there, they can type the new item in. I want to add the new item to the list for future users. I have never used a loop before and the below script ends up in an infinite loop. I run it as a scrip trigger on the Category field as an OnObjectExit. I was hoping that once the item was entered into the field the script would loop through the existing list and exit if it found the item already exists. If it did not find the word it would add it to the list. Can someone help me with this please??
comment Posted June 27, 2020 Posted June 27, 2020 (edited) First, there is no need for a loop here. You can simply check if the entered value is present in the value list used by the drop-down: Set Variable [ $category ; Data::dataCategory ] If [ IsEmpty ( FilterValues ( $category ; ValueListItems ( "" ; "YourValueListName" ) ) ) ] Go to Layout [ "Values" ] New Record Set Field [ Values::category ; $category ] Go to Layout [ original layout ] End If If you wanted to do this by checking every record in the Values table, you would have to make sure to raise a flag when a match is found. Otherwise you would not be able to tell whether the loop was exited because a match was found, or the loop had simply reached the last record: Set Variable [ $category ; Data::dataCategory ] Go to Layout [ "Values" ] Show All Records Go to Record [ First ] Loop Set Variable [ $match ; $category = Values::category ] Exit Loop If [ $match ] Go to Record [ Next; Exit after last ] End Loop If [ not $match ] New Record Set Field [ Values::category ; $category ] End If Go to Layout [ original layout ] -- Caveat: untested (both). Edited June 27, 2020 by comment
Greg58 Posted June 27, 2020 Author Posted June 27, 2020 That works fine. Thanks for your help here. Always learning. Greg
Recommended Posts
This topic is 1610 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now