New question: I have this template that populates my Kobo collections column. (Non-composite, Action Chains single-field edit).
Code:
program:
genre = $#subjects;
colls = strcat(
## if $$#purchasecost == '0.00' then 'Freebies,' fi,
if 'Omnibus' in $#admintags then 'Omnibuses,' fi,
if 'overdrive' in approximate_formats() && !$purchasesource then 'Loans,' fi,
if $#booktype=='Fanfiction' then list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction: \1,') fi,
if 'public domain' inlist $#admintags then 'Public Domain,' fi,
if '^Cozy Mystery$' inlist genre then 'Cozy Mysteries,' fi,
if '^Horses$' inlist genre then 'Horses,' fi,
if 'Folktales & Mythology' inlist genre then 'Folktales & Mythology,' fi,
if '^Science Fiction$' inlist genre then 'Science Fiction,' fi,
if '^(Fantasy|Paranormal)$' inlist genre then 'Fantasy & Paranormal,' fi,
);
if colls == '' then colls = strcat($#booktype, ',') fi;
new_colls = list_union($#kobocoll, colls, ',')
The strcat lines generates various entries, line 16 fallsback to #booktype if there's nothing generated, and line 18 merges with the existing entries. (Being able to add additional entries for individual books is why I don't use a composite column here.)
Sometimes this merging results in leftover #booktype entries, due to my workflow (running the column update when there's a #booktype but no #subjects). Less common, but also happens when adding a new entry to the strcat and bulk-updating.
A real example:
A book with 'Fiction' in #booktype, 'Science Fiction' in #subjects, and an existing #kobocoll value of 'Fiction'
colls returns 'Science Fiction'
new_colls then produces 'Fiction, Science Fiction'
What is the best way to remove 'Fiction' from this without it getting merged back in? A list_difference, but I'm having trouble figuring out what order to put things in