简体   繁体   中英

Pulling Trello card members into google sheet

I'm sure this is insanely simple but I've been bashing my head against it on and off for a week now and getting nowhere. I'm pulling details of Trello cards into a google sheet with the ultimate aim of sending an email to the members of any Trello card from a given list that's exceeded a certain number of days since the last activity.

I'm able to get the cards and relevant fields from Trello using

//get all cards from board   
var url = "https://api.trello.com/1/boards/<board id>/cards?filter=open&fields=name,idList,url,dateLastActivity,idMembers,idLabels&key=<key>&token=<token>";

var get = UrlFetchApp.fetch(url);

and then to parse the return

//parse JSON 
var dataSet = JSON.parse(get);

The problem I've encountered is that where there's more than one member of a card the IDs are returned as a comma seperarated list within a sub-array like this

{idMembers=[member_id, member_id, member_id], idLabels=[label_id], name=card_name, dateLastActivity=date, id=card_id, idList=list_id, url=https://trello.com/c/XXxxxXXxx/blahblahblahblahblahblah}

Looping through parsed JSON and pushing the output to a new array all the member IDs are still all together for each card but when they're passed to the spreadsheet only the first member is making the trip. Code below

for (i = 0; i < dataSet.length; i++) {
data = dataSet[i];

rows.push([data.id, 
           data.name,
           data.idList,
           data.dateLastActivity,
           data.idMembers,
           data.idLabels,
           data.url,              
          ]);
}

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("SheetName");
var last_row = sheet.getLastRow();
var last_column = sheet.getLastColumn();
sheet.getRange(2,1,last_row,last_column).clear();  
dataRange = sheet.getRange(2, 1, rows.length, 7);
dataRange.setValues(rows);

I've tried looping through the array again to seperate out the member IDs

for(j = 0; j < data.idMembers.length; j++) {

but that hasn't helped and I'm not sure it's even along the right lines to a solution. I'm not even sure the problem's in the code and not the google sheet's handling of comma separated values.

In the spreadsheet I don't much care (at the moment) whether I get repeated cards with a single member ID on each, an additional column for each member ID or all the member IDs together in a single cell I just want all the member IDs so I can hassle them to deal with their abandoned cards clogging up my lists.

Any and all suggestions gratefully received

Try this code, using join :

rows.push([data.id, 
           data.name,
           data.idList,
           data.dateLastActivity,
           data.idMembers.join(),
           data.idLabels,
           data.url,              
          ]);

That worked for me, gives list of members, devided by comma: 5467844a...,52cd1e6d27...,55bf2a090...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM