Troubleshooting: Calling t.set("card", "shared", "name", "new name") not changing card name (PowerUp)

Hi everyone,

this code is support to do something very simple: add a “Cleanup” button to a board. When clicked, it finds all cards that have a tomato (pomodoro) emoji in their name. It parses the name and replaces parts of the text. Then tries to save the new name using t.set… and that’s what I can’t get to work.

The powerup is finding the cards. It is generating the new name I want. But the call to t.set() does not seem to do anything.

I tried putting all t.set promises in an array and returning it as a promise.all response, didn’t make any difference.

I’m obviously missing something extremely basic……………

……… can you let PLEASE let me know what it is? :wink:


  'board-buttons': function(t, opts) {
    return [{
      text: 'Clean Up',
      callback: function(t) {
        return'id', 'name').then(function(cards) {
          var promises = []; 
          for (var i = 0; i < cards.length; i++) {
            if (cards[i]["name"].match("🍅")) {
              var card = cards[i];
              var title = card["name"];
              var matches = title.match(/\[(\d+)\]/);
              var sets = 0;
              if (matches) { //not the first pomodoro for this task
                sets += parseInt(matches[1]);
              title = title.replace(/\s* \[[0-9.]+\]/, ''); //remove previous total of pomodoros from title
              matches = title.match(/^([^ ]+) 🍅\s*/); //get number of pomodoros
              if (!matches || typeof matches[1] === 'undefined') { //something's missing 
                reject("failed to parse " + title);
              sets += Math.ceil(matches[1]);
              title = title.replace(matches[0], "") + " [" + sets + "]";
//……………TO HERE: (the following line does not seem to do ANYTHING, ARRRH!!
              promises.push(t.set(card["id"], "shared", "name", title).catch(function(err){console.log(err);}));
//Note - this DOES print "finished running"… even though nothing seems to be saved
          return Promise.all(promises).then(function(result){console.log("finished running")});
      condition: 'edit'

I think you’re actually looking to use the Trello REST API client.

t.set() is used to store data specific to your Power-Up that it might rely on. Think of it as a small, private DB inside of Trello for you to use. It isn’t used to update fields on a card nor board. The only write action a Power-Up can do out of the box is add an attachment to a card via t.attach().

For more write permissions, you’ll need to use the Trello REST API. This will allow you to update card names, descriptions, etc. Using the API requires that you ask the user to grant your application access via the authorization flow.