Category: Tips & Tricks
Working with tags
I’ve been working with tags in different applications for a while and every time I use them, I write the functionality from scratch. It’s not complicated, but by rewriting the code, I always tend to neglect safety checks and nice to have features.
What are tags? It’s a string that contains elements, aka tags, that are separated by a comma:
- jan,feb,dec
- newsletter 08-24, holiday card 2024, invitation summer party 2025
Yesterday, Stephan posted in the TapForms forum requesting the same functionality. While I shared a solution using my code, it sparked an idea. The result is a class that encapsulates all tag handling and includes features such as sorting and tag removal. Here’s an example of using the class with a prompter to add or remove a tag from a field. The documentation} contains a detailed description of all features.
This script uses all records of the currently selected search. But it can work on a saved search, or on all records as well. Just comment/uncomment the respective code sections.
For the script to work, the field id constants nameid and tagsid need to be defined according to your form. nameid is used in the console log to provide some infos on which record the script is running. tagid is the field where you collect your tags.
// load tagHandler class
document.getFormNames("Scripts").runScriptNamed("tagHandler");
// global variables needed by the Prompter
var prompterVarTask;
var prompterVarText;
function callbackSetTag() {
const name_id = 'fld-xxx';
const tags_id = 'fld-xxx';
if (!prompterVarTask){
console.log("Task not defined! Aborting!", "#ff0000");
return;
}
// get records from current search
let recs = search.getRecords();
// // get records from a saved search
// let recs = form.getSearchNamed('Selected').getRecords();
// // use all records
// let myRecords = form.getRecords();
console.log('Found ' + recs.length + ' records');
for (rec of recs){
console.log("Processing " + rec.getFieldValue(name_id))
// load initial values
let tags = new tagHandler(rec.getFieldValue(tags_id));
// check task to be performed
if (prompterVarTask == 'add tag'){
// add new tag
tags.add(prompterVarText);
} else if (prompterVarTask == 'delete tag'){
// add new tag
tags.remove(prompterVarText);
}
// save new tags
rec.setFieldValue(tags_id, tags.toString(", "));
console.log("Updated tags: " + tags.toString(", "));
}
document.saveAllChanges();
};
function setTag(){
let task = ['add tag', 'delete tag'];
let prompter = Prompter.new();
prompter.addParameter('Select Task', 'prompterVarTask', 'popup', task)
.addParameter('Tag', 'prompterVarText', 'text')
.show('Add Tag to current record', callbackSetTag);
}
setTag();
Installation
The HTML Export Handler script is installed using the scriptHandler script about which you can learn more over here. It is installed in the Scripts form.
Dependencies
Following helper scripts is needed
- tagHandler
This script can be installed using the scriptHandler script.
Author
- Daniel Leu, info@danielleu.com
Do you like this script? Are you using it? Please consider supporting me by buying me a coffee!
Thanks!
Last modified: Feb 9, 2026 4:32:10 AM
