Jump to content
Server Maintenance This Week. ×

Adding unique words to a list


This topic is 1400 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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??

image.png.23eb900528f563ad0e513aec73eceb47.png

Link to comment
Share on other sites

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 by comment
Link to comment
Share on other sites

This topic is 1400 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.