SUMMARY
When using GetGrist’s formula column, Python’s native function [array].append() returns an error:
#AttributeError
The formula it was being used on in pertinent part:
return $Tags.append("Reminder")
Where “$Tags” is a field that is a “Choice List”.
update- the attributeError is cause by the fact that the Choice List is a ‘tuple’ object and is neither a list nor an array, and therefore it has no attribute ‘append’.
To correct this problem, I used a function to convert the tuple to a list ( list([tuple]).append([string]) ). This solved the error, but the formula still does not return anything useful.
GOAL
- I have a field/column called TAGS that is typed as a “Choice List” field.
- When a user adds a “due date” to the record, I would like my TAGS field to automatically have the choice “Reminder” added to the existing list of choices on that record.
DISAMBIGUATION
To be clear, I am asking how to append a value that is already available as a choice in a particular field , therefore this thread does not apply : How to auto-add choices on a Choice List Column?
SETUP DETAILS
Here are the options / choices that are available in the TAGS field:
- Complaint
- Check-in
- Reminder
- Training, etc
And here is the first part of my formula, the boolean test, that is useful and works as desired. It returns true whenever a user updates a records Notification_DueDt and forgets to update the TAGS field with “Reminder”:
if "Reminder" not in rec.Tags and $Notification_DueDt != None :
return ...
Now, here are different versions of the the entire formula (both the boolean test and the array / list modification function) , and this last part is the portion that is giving me trouble and refuses to return the desired values.
* Formula Version 1:
Here is the original version of the formula (which is the version I was using before learning that GetGrist choice lists return a tuple instead of an array or list):
if "Reminder" not in rec.Tags and $Notification_DueDt != None :
return $Tags.append("Reminder")
This version was completely scrapped for the reasons mentioned earlier (that a choice list returns an immutable tuple as opposed to an array or list).
* Formula Version 2 … no official error but still problematic
The following new formula that converts the TUPLE into a LIST and then attempts to append the new list value still suffers from odd behavior. This new formula,
if "Reminder" not in rec.Tags and $Notification_DueDt != None :
listTags = list($Tags).append("Reminder")
return listTags
will return existing tags if I do NOT use “.append(‘Reminder’)” on line 2. But as soon as I use the formula exactly as typed above (including the “.append…” portion), it returns nothing.
REQUEST
- Please share thoughts regarding how to append a value to an array using native python functions or getGrist functions.
- Any thoughts on a work around if the python native function “append” will not work?
------------FINDINGS AFTER ORIGINAL POSTING------------
Upon further investigation, the specifics of the error are as follows:
AttributeError: 'tuple' object has no attribute 'append'
And after a quick google search, found this out:
A tuple is a list which cannot be rewritten once created so it cannot be modified at all. and you have used append() which adds some data to the tuple therefore there is this error. Instead of using a tuple declare it as a list using the square brackets.