Jump to content

Scripts, Value List items and Set Field?


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

Recommended Posts

How do I set a field with a value list item from a script, from a set of tick box values? .. or remove a value list item, but leave whatever else is there alone?

Looks like GetValue with the name of the value list and the position # of the value, but I'm sure that also means that if I change that value list, I need to change any scripts that reference them by position # too..

Something like detecting if a string is already there, and if not add it, surrounded by C/Rs, unless it's the first item entry?

For the first time a field is set, I presume I could just Set Field (field ; "Value List Item"), and if there's only one entry/line in it, just clear it.  But if there's already a value there, I just want to select an additional one.

Link to comment
Share on other sites

If you attach a value list to a field, you designate that value list entry option (list, menu, check box, radio) to be *THE* input method.

If you are trying to capture the user's selection from the value list don't want that selection into the field as-is then you're misusing the value list input.

And there would be no need to try and read values from the value list directly with GetValue().

So I think you need to explain this with a example and some screenshots because it sounds like you're going down a wrong path.

Perhaps this will be a case where you do not want to have multiple values stored in one field but that you need to create records in a join table.

So walk us through your specific example.

Link to comment
Share on other sites

A field formatted as a checkbox set hold a return-separated list of selected values.

To add a value to the field, you could simply set the field to:

List ( YourTable::YourField ; "New Value" )

There is no need to select the value from a value list (unless you want to, for some other reason). Naturally, if the added value is not a member of the value list associated with the checkbox field, then the field will not display a check for it (or display it at all).

If you are not sure if the new value is already in the field, then use the UniqueValues() function at the end. Or test first by:

IsEmpty ( FilterValues ( "New Value" ; YourTable::YourField ) )


Removing a value is a bit more tricky. Basically, the process is: (1) add leading and trailing returns to the list; (2) substitute the removed value - with leading and trailing return - by a single return and (3) remove the added returns. 

 

Edited by comment
Link to comment
Share on other sites

  • 1 month later...
  • Newbies

I would like to expand on this question if I may.  I have a value list composed of 10 values.  The field is set to display as checkboxes.  Now I want to have a push button to check all boxes.  Likewise I want a button to uncheck all checkboxes.  I don’t have a problem with the unchecking part but I do with checking all of the boxes.

The script I made has one line which uses the “Set Field” function.  For example I have Entered:

Set Field[table::field, “value list item1”] and it checks off that one checkbox.  However, the problem comes in when I try to set more than one value.  I have tried:

Set Field[table::field,”value list item1|value list item2” but neither get checked.  I have tried other delimiters such as the comma, semi-colon, colon and a space but nothing seems to work.  Can anyone tell me what I might be doing wrong?

Thanks in advance.

Link to comment
Share on other sites

You were so close! A field that is formatted with a checkbox value list delimits each value with a return ¶.

Set Field[table::field; "valuelistitem1¶valuelistitem2"] or

Set Field[table::field;  List ("valuelistitem1" ; "valuelistitem2" ; "valuelistitem3" ) ] or

use the value list name

Set Field[table::field; ValueListItems ("" ; "MyValueListName") ]

 

to clear

Set field [table::field, ""]

Link to comment
Share on other sites

  • Newbies

Thank you for the quick reply.  I don’t think I would have ever tried the return as a delimiter but it definitely makes sense. Thank you so much. I looked for the answer on the web just about all day yesterday and I came up empty. I joined the forum today and had my solution within minutes of posting my question. This is an extremely valuable forum!

Link to comment
Share on other sites

This topic is 1369 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.