Action

Tag Converter

Posted by raigmcclellan, Last update about 4 years ago - Unlisted

I realized that how I was using a particular tag had moved beyond what that tag was called and wanted to rename that tag. This is a quick script that will prompt you for the tag you want to change and what you want to change it to, then update all drafts with that tag.

Steps

  • script

    // Tag Converter
    // Changes the name of a tag on all drafts with that tag
    
    
    // Create prompt to ask user for the tag they would like to change and what they would like to change it to.
    
    var p = Prompt.create();
    
    p.title = "Tag Selector";
    p.message = "Enter names of tags you would like to rename.";
    
    p.addTextField("original", "Current Tag to be Renamed","", {"placeholder": "Original Tag"});
    p.addTextField("new", "New Name", "", {"placeholder": "New"});
    p.addButton("Done");
    
    p.show();
    
    var original = p.fieldValues["original"];
    var newTag = p.fieldValues["new"];
    
    // Find all drafts with the original tag, add new tag, remove old, and update draft.
    
    var draftList = Draft.query("", "all", [original]);
    console.log(draftList)
    
    for (var item of draftList) {
    	item.addTag(newTag);
    	item.removeTag(original);
    	item.update();
    }

Options

  • After Success Nothing
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.