Class: Card

TrelloEntities.Card(data)

The Card class represents a Card in Trello. Not every Notification will have a card object associated with it because all Trellinator webhooks are registered at the board level (so for example a notification about the name of a list being updated won't have a card object associated with it).

Cards are loaded from Boards or Lists, and must be created in a List.

Constructor

new Card(data)

Parameters:
Name Type Description
data

(Object} key/value pairs of information, must at least contain "id", can basically just pass in response from Trello API

Source:
Examples
new Notification(posted).card().postComment("Hello world!");
new Trellinator().board("Some Board").card(new RegExp("Find me.*"));
new Notification(posted).board().list("ToDo").cards().first().moveToNextList();
Card.create(new Trellinator().board("Some board").list("ToDo"),"Do it!");

Methods

(static) Card.create(list, data)

Create a new card in the given list with the given name, or key/value pairs in an object, using parameters from https://developers.trello.com/reference/#cards-2

Parameters:
Name Type Description
list List

a List to add the card to

data string | Object

either a card name to use or an Object of key/value pairs

Source:
Examples
Card.create(new Trellinator().board("Some Board").list("ToDo"),"Hi there!");
Card.create(new Trellinator().board("Some Board").list("ToDo"),{name: "Hi there!",pos:"top"});

(static) Card.findOrCreate(list, data)

Find a card or create it if it doesn't already with either just a string name, or an Object with key/value pairs from https://developers.trello.com/reference/#cards-2 exist, in the given list. The card can exist anywhere on the same board as the target list, but will be created in the target list if it doesn't exist.

Parameters:
Name Type Description
list List

a List object to find or create the card in

data string | Object

either the name of the card, or an Object with at least a name attribute to be used to find the card, and then data to be used when creating the card

Source:
Example
Card.findOrCreate(new Trellinator().board("My Board").list("Inbox"),"New Card Name");

(static) this.addChecklist(name, callback, position)

Add a checklist to this card, or pass an existing checklist into the callback if it already exists on this card

Parameters:
Name Type Description
name string

The name of the checklist to add

callback function

a callback which will recieve the new or existing Checklist object to add items to it

position string

(optional) top, bottom, a number, defaults to "bottom"

Source:
Example
new Notification(posted).movedCard("ToDo").addChecklist("Do Stuff",function(cl)
{
    cl.addItem("Did you do this yet?");
});

(static) this.addLabel(label_name)

Add a label to the card by name, whether it already exists in the board or not

Parameters:
Name Type Description
label_name string

The name of the label to add

Source:
Example
new Notification(posted).card().addLabel("New");

(static) this.addMember(member)

Add a member to this card

Parameters:
Name Type Description
member Member

a Member object to add to the card

Source:
Example
var notif = new Notification();
var created = notif.createdCard();

notif.board().members().each(function(member)
{
    notif.card().addMember(member);
});

(static) this.addNewLabels(new_labels)

Add new labels that don't already exist to a card by name. You should just use the addLabel() method instead

Parameters:
Name Type Description
new_labels Array

an array of label names to create on this board and added to the card

Source:

(static) this.addSticker(sticker, top, left, rotate, z)

Add a custom or default sticker.

Parameters:
Name Type Description
sticker string

To add a custom sticker, pass in the ID of a custom sticker, fetched with Member.customStickers, for example new Trellinator().customStickers() if your custom sticker list was created by your Trellinator user. Note that custom stickers are only avialable in business/enterprise class accounts. Otherwise you can pass in a predefined sticker from this list:

Standard stickers (available in free accounts):

  • check
  • heart
  • warning
  • clock
  • smile
  • laugh
  • huh
  • frown
  • thumbsup
  • thumbsdown
  • star
  • rocketship

Premium stickers (business/enterprise class only):

  • taco-love
  • taco-confused
  • taco-cool
  • taco-angry
  • taco-celebrate
  • taco-robot
  • taco-alert
  • taco-active
  • taco-money
  • taco-reading
  • taco-trophy
  • taco-sleeping
  • taco-pixel
  • taco-proto
  • taco-embarrassed
  • taco-clean
  • pete-happy
  • pete-love
  • pete-broken
  • pete-alert
  • pete-talk
  • pete-vacation
  • pete-confused
  • pete-shipped
  • pete-busy
  • pete-completed
  • pete-space
  • pete-sketch
  • pete-ghost
  • pete-award
  • pete-music
top int

(optional) y co-ordinate between -60 and 100 default 0

left int

(optional) x co-ordinate between -60 and 100 default 0

rotate int

(optional) degree of rotation between 0 and 360 default 0

z int

(optional) z-index (ie. if this should sit "on top" of other stickers) 0 is highest, ie. "on top" of everything else, and is the default

Source:
Example
new Notification(posted).card().addSticker("pete-happy");

(static) this.allChecklistsComplete()

Return true if all checklists on a card are complete

Source:
See:
  • Notification.completedAllChecklists()
Examples
new Trellinator().board("Some Board").list("Doing").cards().each(function(card)
{
    if(card.allChecklistsComplete())
        card.moveToNextList();
});
//This is not part of this class, but a common use case you 
//should be aware of instead
new Notification(posted).completedAllChecklists().moveToNextList();

(static) this.applyLabelIds(label_ids)

Add existing labels to a card by ID. You should just use the addLabel method instead

Parameters:
Name Type Description
label_ids Array

an array of label_ids

Source:

(static) this.archive()

Archive this card

Source:
Example
new Notification(posted).movedCard("Done").archive();

(static) this.attachFile(data)

Download a file from a URL to Google Drive, then add it as a link to the card. I can't see a good way to add a file directly by URL either from the internet or from Google Drive so this should be updated at some point.

Parameters:
Name Type Description
data string | Object

either a string that is a fully formed URL, or an object that contains at least either an attribute link or url, and optionally one of these as well as a name attribute

Source:
Example
var notif = new Notification(posted);
card.attachFile(notif.card().attachments().first().link());

Add a link attachment to this card

Parameters:
Name Type Description
data string | Object

either a string that is a fully formed URL, or an object that contains at least either an attribute link or url, and optionally one of these as well as a name attribute

Source:
Examples
var notif = new Notification(posted);

var notif.card().addChecklist("Linked Cards",function(list)
{
    notif.board().list("ToDo").cards().each(function(card)
    {
        list.addItem(card.link());
        card.attachLink(notif.card().link());
    });
});
new Notification(posted).card().attachLink({name: "A Popular Search Engine",url: "https://www.google.com/"});
new Notification(posted).card().attachLink({name: "A Popular Search Engine",link: "https://www.google.com/"});

(static) this.attachment(name)

Fetch the first attachment on the card. Name filtering not implemented yet

Parameters:
Name Type Description
name string | RegExp

not yet implemented

Source:
Example
Trellinator.log(new Notification(posted).card().attachment());

(static) this.attachments(name)

Get all attachments on the card, filtering not implemented

Parameters:
Name Type Description
name string | RegExp

name or RegExp, not yet implemented

Source:
Example
new Notification(posted).card().attachments().each(function(att)
{
    Trellinator.log(att);
});

(static) this.board()

Return the Board object that this card is on

Source:
Example
var card = new Notification(posted).card();
card.board().card(card.name()).each(function(loop)
{
    if(loop.id() != card.id())
        loop.postComments("Twinsies with "+card.link());
}

(static) this.boardsLinkedInAttachments()

Return an IterableCollection of all boards linked as attachments

Source:
Example
new Notification(posted).card().boardsLinkedInAttachments().first().list("ToDo").cards().each(function(card)
{
    card.postComment("Ger er done!");
});

(static) this.cardLinkedInDescription()

Return a Card if there is one linked in the description of this card

Source:
Example
new Notification(posted).archivedCard().cardLinkedInDescription().postComment("Your pal was archived");

(static) this.cardsLinkedInAttachments()

Return an IterableCollection of all cards linked as attachments

Source:
Example
new Notification(posted).card().cardsLinkedInAttachments().first().postComment("Hello from over here");

(static) this.checkItemByName(name)

Check any item in any checklist with the given name or matching RegExp

Parameters:
Name Type Description
name string | RegExp

the name of the checklist item to complete, or a RegExp (all matching items will be completed)

Source:
Example
var card = new Notification(posted).archivedCard();
cards.cardsLinkedInAttachments().first().checkItemByName(card.link());

(static) this.checklist(name)

Return a checklist from this card of the given name if it exists or throw InvalidDataException

Parameters:
Name Type Description
name string | RegExp

a name or RegExp to match against the checklist name (first will be returned if multiple match)

Source:
Example
new Notification(posted).movedCard("Done").checklist(new RegExp("Process.*")).markAllItemsComplete();

(static) this.checklists(name)

Return an IterableCollection of Checklist objects optionally filtered by name/RegExp

Parameters:
Name Type Description
name string | RegExp

a string or regex to filter the list by

Source:
Example
new Notification(posted).completedDueDate().checklists(new RegExp("Process.*")).each(function(list)
{
    list.markAllItemsComplete();
});

(static) this.comments(limit)

Return a list of comments from this card

Parameters:
Name Type Description
limit int

(optional) limit the number of comments returned, default limit is 20

Source:
Example
new Notification(posted).card().comments().each(function(comment)
{
    Card.create(new Trellinator().board("Some Board").list("ToDo"),comment);
});

(static) this.copyChecklist(name, to_card, position)

Copy a checklist to another card from this card even if it already exists on the target card and return the new checklist

Parameters:
Name Type Description
name string | RegExp

the name of the checklist to copy, if multiple matches will just take the first found

to_card Card

the card to copy the checklist to

position string

(optional) either top or bottom, or a positive number, defaults to bottom

Source:
Example
var notif = new Notification(posted);
//Copy a checklist to a card if it was moved or added to the ToDo list
notif.board().card("Templates").copyChecklist("Some Procedure",notif.addedCard("ToDo"));

(static) this.copyTo(name, position)

Copy this card to a list on the same board and return the copy

Parameters:
Name Type Description
name string | RegExp

a string list name, or regex (if multiple matches, the first matching list will be used

position string | int

top, bottom or a number

Source:
Example
new Notification(posted).card().copyTo("ToDo","top");

(static) this.copyToList(list, position)

Copy this card to a given List, optionally to a specific position, and return the copy

Parameters:
Name Type Description
list List

a List object to copy this card to

position string | int

either top, bottom or a number

Source:
Example
var list = new Trellinator().board("Some Board").findOrCreateList("ToDo");
//Copy the card to a list ToDo in the board Some Board in position 2
new Notification(posted).card().copyToList(list,2);

(static) this.copyUniqueChecklist(name, to_card)

Copy a checklist from this card, to another card if it doesn't already exist on that card and return either the new checklist or the checklist that already existed

Parameters:
Name Type Description
name string | RegExp

the name of the checklist to copy, can be a string or RegExp, if more than one matches will just copy the first found

to_card Card

the card to copy the checklist to var notif = new Notification(posted); //Copy a checklist to a card if it was moved or added to the ToDo list notif.board().card("Templates").copyUniqueChecklist("Some Procedure",notif.addedCard("ToDo"));

Source:

(static) this.currentList()

Return the List this card is currently in

Source:
Example
new Notification(posted).archivedCard().currentList().archive();

(static) this.customFields()

Get an IterableCollection of all custom fields as raw objects for this card (not really that useful)

Source:

(static) this.customFieldValue(field_name)

Return the value of a custom field by name. This works for all field types, and the value is converted to the appropriate data type based on the type of field (eg. number/date/etc)

If the Custom Fields power up is not enabled this method will attempt to enable it. If it can't be enabled because the board has reached the power up limit, an unexpected exception is thrown.

If a field with the given name doesn't exist it will be created as a text type field

Parameters:
Name Type Description
field_name striung

the name of the field to get the value for on this card

Source:
Example
new Notification(posted).card().customFieldValue("My Field");

(static) this.del()

Delete this card NO UNDO AVAILABLE

Source:
Example
new Notification(posted).movedCard("Done").del();

(static) this.description()

Return the description of this card

Source:
Example
var card = new Notification(posted).changedCardName();

card.setDescription(Trellinator.now().toLocaleString()+" updated to "+card.name()+"\n\n"+card.description());

(static) this.due()

Return the due date for this Card, which can be passed into the constructor of a Date object

Source:
Example
new Date(new Notification(posted).card().due());

(static) this.dueComplete()

Return true if the due date on this card has been marked complete

Source:
Example
var card = new Notification(posted).card();

if(card.dueComplete())
    card.moveToNextList();

(static) this.hasLabel(name)

Return a Label if it is on this card, or false if the label is not on the card

Parameters:
Name Type Description
name string | RegExp

a string or RegExp to match the label name against

Source:
Example
//check if a due date was marked complete on a card with label starting with "Process"
var added = new Notification(posted).addedLabel("Old");

if(added.card().hasLabel("New"))
    added.card().postComment("Something old and something new");

(static) this.id()

Returns the card ID

Source:
Example
new Notification(posted).card().id();

(static) this.isArchived()

Check if this card is archived

Source:
Example
new Notification(posted).archivedCard().isArchived();

(static) this.label(name)

Return a Label if it is on this card, or throw InvalidDataException if it isn't on the card

Parameters:
Name Type Description
name string | RegExp

a string or RegExp to match the label name against

Source:
Example
//check if a due date was marked complete on a card with label starting with "Process"
new Notification(posted).completedDueDate().label(new RegExp("Process.*"));

(static) this.labels(name)

Return an IterableCollection of Label objects that are on this card optionally filtered by name/regexp

Parameters:
Name Type Description
name string | RegExp

a string or RegExp to filter against

Source:
Example
new Notification(posted).card().labels().each(function(label)
{
    Trellinator.log(label.name());
});

Return a link to this card

Source:
Example
var notif = new Notification(posted);
notif.card().cardsLinkedInAttachments().first().checkItemByName(notif.card().link());

(static) this.load()

Reset cached objects and load data from Trello. You may find this is required sometimes to force a reload of an object, but you shouldn't use this habitually.

Source:
Example
new Notification(posted).card().load().currentList();

(static) this.markDueDateComplete()

Mark the due date on this card complete

Source:
Example
//Mark the due date complete on a card that was moved into the Done list
new Notification(posted).movedCard("Done").markDueDateComplete();

(static) this.markDueDateIncomplete()

Mark the due date on this card incomplete

Source:
Example
//Mark the due date complete on a card that was moved into the Done list
new Notification(posted).movedCard("Done").markDueDateIncomplete();

(static) this.member(name)

Return a Member of this card matching the given name/regex

Parameters:
Name Type Description
name string | RegExp

a name or RegExp to match

Source:
Example
new Notification(posted).card().member("iaindooley");

(static) this.members(name)

Return an IterableCollection of Members on this card optionally filtered by name using a string or RegExp

Parameters:
Name Type Description
name string | RegExp

a name or RegExp to filter by

Source:
Example
var card = new Notification(posted).archivedCard();

card.members().each(function(member)
{
    card.postComment("@"+member.name()+" this card was archived");
});

Return a link to this card formatted so that it can be used in a checklist item name such that the link will work on both mobile and web/desktop apps

Source:
Example
var notif = new Notification(posted);
notif.card().mobileFriendlyLink();

(static) this.movedToList()

Return the date/time this card was moved into it's current list

Source:
Example
new Notification(posted).card().movedToList().toLocaleString();

(static) this.moveTo(name, position)

Move a card to a list within the same board

Parameters:
Name Type Description
name string | RegExp

the name or a regex to match a list within the same board to move the card to

position string | int

(optional) top, bottom or a number, default bottom

Source:
Example
new Notification(posted).archivedCard().unArchive().moveTo("Graveyard","top");

(static) this.moveToList(list, position)

Move a card to a given List

Parameters:
Name Type Description
list List

a list object to move the card to

position string | int

top, bottom or a number (defaults to bottom)

Source:
Example
var to_list = new Trellinator().board("Other Board").list("ToDo");
new Notification(posted).createdCard("Doing").moveToList(to_list,"top");

(static) this.moveToNextList()

Move the card to the next list in the same board or throw InvalidDataException if there is no next list

Source:
Example
new Notification(posted).card().moveToNextList();

(static) this.name()

Return the name of this card (also sometimes called the title of the card)

Source:
Example
Trellinator.log(new Notification(posted).card().name());

(static) this.notification()

Return the notification (if any) that originated this card

Source:
Example
new Notification(posted).card().notification().replytoMember("Hai");

(static) this.postComment(comment_text)

Post a comment to this card

Parameters:
Name Type Description
comment_text string

the text to post

Source:
Example
var card = new Notification(posted).movedCard("Done");

card.members().each(function(member)
{
    card.postComment("@"+member.name()+" this card was moved to the Done list");
});

(static) this.removeAllLabels()

Remove all labels from this card

Source:
Example
new Notification(posted).movedCard("Done").removeAllLabels();

(static) this.removeAllMembers()

Remove all members from this card

Source:
Example
new Notification(posted).movedCard("Done").removeAllMembers();

(static) this.removeAllStickers()

Remove all stickers from a card

Source:
Example
new Notification(posted).card().removeAllStickers();

(static) this.removeChecklist(checklist)

Remove a checklist from this card

Parameters:
Name Type Description
checklist Checklist

the checklist to remove

Source:
Example
var card = new Notification(posted).movedCard("Done");
card.removeChecklist(card.checklist("Some Process"));

(static) this.removeChecklistItemByName(name)

Removes any item from any checklist on this card matching the string or RegExp passed in

Parameters:
Name Type Description
name string | RegExp

the text (exact or regex match) of the checklist item to remove

Source:
Example
new Notification(posted).card().removeChecklistItemByName(new RegExp("Milk.*"));

(static) this.removeDueDate()

Clear the due date on this card

Source:
Example
//Remove the due date on a card that was moved to the Backlog list
new Notification(posted).movedCard("Backlog").removeDueDate();

(static) this.removeLabel(label)

Remove a label from this card by label object

Parameters:
Name Type Description
label Label

a Label object to remove from this card

Source:
Example
var notif = new Notification(posted);
notif.card().removeLabel(notif.board().label("Some Label"));

(static) this.removeMember(member)

Remove a member from this card

Parameters:
Name Type Description
member Member

a Member object to remove from this card

Source:
Example
var notif  = new Notification(posted);

if(new RegExp("Remove.*").test(notif.addedComment().text()))
{
   notif.card().removeMember(notif.member());
}

(static) this.setCustomFieldValue(field_name, field_value)

Set the value of a custom field. Automatically converts the value to the correct type for the API, including looking up dropdown options etc.

If the Custom Fields power up is not enabled this method will attempt to enable it. If it can't be enabled because the board has reached the power up limit, an unexpected exception is thrown.

If a field with the given name doesn't exist it will be created as a text type field.

Parameters:
Name Type Description
field_name string

the name of the field to get the value for on this card

field_value string | Date | int | float | double | boolean

the value to set

Source:
Example
new Notification(posted).card().setCustomFieldValue("My Field","Hi there");

(static) this.setDescription(desc)

Set the description of this card

Parameters:
Name Type Description
desc string

The description to set on the card

Source:
Example
var card = new Notification(posted).archivedCard();
card.setDescription("Archived on: "+Trellinator.now().toLocaleString()+"\n\n"+card.description());

(static) this.setDue(datetime)

Set the due date on this card

Parameters:
Name Type Description
datetime Date

a Date object

Source:
Example
//When a card is created in the ToDo list set it due in 3 days time at 9am 
new Notification(posted).createdCard("ToDo").setDue(Trellinator.now().addDays(3).at("9:00"));

(static) this.setName(name)

Set the name of this card

Parameters:
Name Type Description
name string

the new name for the card

Source:
Example
new Notification(posted).card().setName("UPDATED");

(static) this.shortId()

Return the short ID of this card

Source:
Example
var notif = new Notification(posted);
notif.card().shortId();

(static) this.unArchive()

Unarchive this card

Source:
Example
new Notification(posted).archivedCard().unArchive();

(static) this.weekDaysSinceCreated()

Number of days excluding saturday and sunday since this card was created

Source:
Example
new Notification(posted).card().weekDaysSinceCreated().toLocaleString();    

(static) this.whenCreated()

Return a Date object representing the creation date of this card

Source:
Example
new Notification(posted).card().whenCreated().toLocaleString();