Skip to content

Instantly share code, notes, and snippets.

@iaindooley
Last active September 10, 2020 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaindooley/045f90b78b2db37f5f7f6a966551a290 to your computer and use it in GitHub Desktop.
Save iaindooley/045f90b78b2db37f5f7f6a966551a290 to your computer and use it in GitHub Desktop.
Copy a template and retain links
var template_board_link = "https://trello.com/b/lIXgjCeC/sample-linked-template";//replace with your actual link
var project_template_name = "Some Project";//replace with the name of your project
var template = new Board({link: template_board_link});
console.log("Copying from: "+template.name());
var new_board = template.copy(project_template_name);
//replace "Main Tasks" if your template board structure is different
//from the sample above
new_board.list("Main Tasks").cards().each(function(card)
{
replaceLinks(card);
});
console.log("Your new board is ready at: "+new_board.link());
function replaceLinks(card)
{
try
{
//replace "Checklist" with the actual checklist name
card.checklist("Checklist").items().each(function(item)
{
var existing = item.linkedCard();
var replacement = new_board.card(existing.name());
item.setName(replacement.link());
replaceLinks(replacement);
});
}
catch(e)
{
Notification.expectException(InvalidDataException,e);
}
try
{
var parent = card.cardsLinkedInAttachments().first();
card.attachment(parent.link()).remove();
card.attachLink(new_board.card(parent.name()).link());
}
catch(e)
{
Notification.expectException(InvalidDataException,e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment