|  01-30-2014, 06:22 PM | #1 | 
| Calibre Companion Fanatic            Posts: 873 Karma: 1088610 Join Date: Nov 2006 Device: Galaxy Note 4, Kindle Voyage | 
				
				Looking for how to create a custom column based on a tag
			 
			
			I would like to create a custom column that works this way: If a book has a specific tag (in this case "First"), make the column that tag name. Otherwise, make it the series name if one exists. Otherwise, make it the string "Uncategorized". I know how to do all of this except for checking for a specific tag on a book that might have more then one tag. {:'first_non_empty(field('tag'), field('Series'),'Uncategorized')'} I need to replace field('tag') with something that will look for the specific tag, but I have no idea what to put in instead. Any advice or help would be appreciated. Thanks. | 
|   |   | 
|  01-30-2014, 06:50 PM | #2 | |
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | 
			
			http://manual.calibre-ebook.com/temp...-not-found-val Quote: 
 use "," as separator, val will be field('tags') and you want to search for string "First", then return found_val "First". not_found_val should return empty "" which first_non_empty should skip over, I think. Personally, I think you should use general program mode for this: Code: program:
	first_non_empty(
		str_in_list(
			field('tags'),
			",",
			"First",
			"First",
			""
		),
		field('series'),
		"Uncategorized"
	) | |
|   |   | 
|  01-30-2014, 06:51 PM | #3 | |
| Calibre Companion Fanatic            Posts: 873 Karma: 1088610 Join Date: Nov 2006 Device: Galaxy Note 4, Kindle Voyage | Quote: 
 | |
|   |   | 
|  01-30-2014, 08:01 PM | #4 | 
| Well trained by Cats            Posts: 31,251 Karma: 61360164 Join Date: Aug 2009 Location: The Central Coast of California Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A | |
|   |   | 
|  01-30-2014, 08:06 PM | #5 | |
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | Quote: 
 the "program:" at the beginning set the interpreter to use general program mode, which is why I included it.  Much more readable this way, isn't it?   Last edited by eschwartz; 01-30-2014 at 08:10 PM. | |
|   |   | 
|  01-30-2014, 10:48 PM | #6 | |
| Calibre Companion Fanatic            Posts: 873 Karma: 1088610 Join Date: Nov 2006 Device: Galaxy Note 4, Kindle Voyage | Quote: 
 | |
|   |   | 
|  02-10-2014, 02:20 PM | #7 | 
| Calibre Companion Fanatic            Posts: 873 Karma: 1088610 Join Date: Nov 2006 Device: Galaxy Note 4, Kindle Voyage | 
			
			One more question. As suggested, I am using this: str_in_list( field('tags'), ",", "First", "First", "" ), as part of my column definition. Is there a way to search for the first tag that doesn't match a specific substring. I have a bunch of tags that start with "FiS-", and I would like to get the first tag that isn't one of them. Something like str_not_in_list( field('tags'), ",", "FiS-*", ##Found Tag##, "" ), Is there some way to do that? Thanks. | 
|   |   | 
|  02-11-2014, 12:52 AM | #8 | |
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | 
			
			Using list_difference() [see here]: Quote: 
 PHP Code: 
			So try this: PHP Code: 
			 It appears that the "PHP" BBCode is better than the "CODE" BBCode for this CODE. | |
|   |   | 
|  02-11-2014, 09:33 AM | #9 | 
| Calibre Companion Fanatic            Posts: 873 Karma: 1088610 Join Date: Nov 2006 Device: Galaxy Note 4, Kindle Voyage | 
			
			Excellent, thanks. One question: Is there any way to use a regex string in the "comma,separated,list,of,excluded,tags" so that I don't have to enumerate each one. I have about 10 of them, and I add new ones occasionally as well. They all start with "FiS-". I tried "FiS-.*" and that didn't work. Thanks for all the help. Last edited by kaufman; 02-11-2014 at 10:42 AM. | 
|   |   | 
|  02-11-2014, 02:28 PM | #10 | |
| Ex-Helpdesk Junkie            Posts: 19,421 Karma: 85400180 Join Date: Nov 2012 Location: The Beaten Path, USA, Roundworld, This Side of Infinity Device: Kindle Touch fw5.3.7 (Wifi only) | 
			
			list comparisons do not accept regexes. Try using list_re() [see here]: Quote: 
 PHP Code: 
			PHP Code: 
			Last edited by eschwartz; 02-11-2014 at 02:36 PM. | |
|   |   | 
|  02-12-2014, 11:15 AM | #11 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | 
			
			You could also use list_re to create a sublist of the source, then list difference to see if the source contains any other elements.
		 | 
|   |   | 
|  | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Custom column returns value based on value of another custom column? | calvin-c | Calibre | 3 | 09-14-2013 02:24 PM | 
| how to move value(s) of tag column to a custom made column | zoorakhan | Library Management | 0 | 12-08-2012 03:53 AM | 
| Automatically tag based on column info? | Iocane | Library Management | 3 | 09-10-2012 12:40 PM | 
| Y/N custom column in Tag Browser? | matthewdeans | Calibre | 15 | 08-12-2011 02:01 PM | 
| create custom format column | blaubach | Calibre | 12 | 09-17-2010 03:22 PM |