Hi, I have a google app script that returns the data from the activity logs from my board and the user and created by fields as well. I was able to insert the whole payload into a cell in the google sheet. This was done for every log, so a row is filled with cells (each is a column) each cell contains the payload. Each cell looks like this:
{created_at=16599705890539942, data={“board_id”:2984947278,“group_id”:“topics”,“is_top_group”:true,“pulse_id”:3002211794,“pulse_name”:“Kayla”,“column_id”:“contact_position9”,“column_type”:“color”,“column_title”:“Contact Position”,“value”:{“label”:{“index”:1,“text”:“Owner”,“style”:{“color”:“#00c875”,“border”:“#00B461”,“var_name”:“green-shadow”},“is_done”:true},“post_id”:null},“previous_value”:{“label”:{“index”:3,“text”:“Consultant”,“style”:{“color”:“#0086c0”,“border”:“#3DB0DF”,“var_name”:“blue-links”},“is_done”:false},“post_id”:null},“is_column_with_hide_permissions”:false}, user_id=32384900}
I know want to take this data and split it into separate fields for each value. For example I want a column “board_id” and then the value from all the logs below. I want to do this for each field in data as well as for “user_id” and “created_by”. I have written a script to do this but it doe not seem to work. It changes the first cell to “Success” which means it has read the data but on a new sheet where I am sending the data it is not there. Below is the script to do this:
function split_values(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getSheetByName(“Google script”); //Your original Sheet Name
var sheet2 = ss.getSheetByName(“Sheet6”); //Your modified Sheet Name
var cellRange = sheet.getDataRange();
var cellValues = sheet.getDataRange().getValues(); //All values from original sheet.
var arrayItems = ;
var array_to_print = ;
cellValues.forEach(function(row, index) {
var cell = sheet.getRange(index+1, 1)
Logger.log(cell.getValue())
if(cell.getValue() != “Success”){ //Check if we have already parsed this row
cell.setValue(“Success”) //If not, parse it and set status as Success.
var split_item = row[0].split(/data: /g);
Logger.log(split_item);
for(var i=1;i<split_item.length;i++){
var item = split_item[i].split(/, ‘board_id/)[0].split(/, ‘board_id/)[0].replace(/’/g,’"')+ ‘}’;
item = JSON.parse(item);
arrayItems.push(item);
}}
});
for (var i = 0; i < arrayItems.length ; i++) {
array_to_print.push([arrayItems[i].board_id])
}
Logger.log(array_to_print)
if(array_to_print.length>0){
sheet2.getRange(sheet2.getLastRow()+1, 1,array_to_print.length,1).setValues(array_to_print);
}
}
I have spent 2 weeks trying to figure this out. Any help would be greatly appreciated.