Help

Get the time when value was updated from cell

Topic Labels: Automations
888 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Edouard_Verstra
4 - Data Explorer
4 - Data Explorer

Hi :wave: ,
This is my script now:

let ranking = base.getTable("Ranking");
let record = await ranking.selectRecordsAsync();

for (let line of record.records){
    let tweet_url = line.getCellValue("tweet_url");

    if (tweet_url != null){
        let status_location = tweet_url.indexOf("status");
        let id = tweet_url.slice(status_location+7);
        let link = `https://api.twitter.com/2/tweets/${id}?tweet.fields=created_at`;
        let token = "AAAAAAAAAA2pr2rjtB9ewZtrXtic5AXxsWdAC";
        let response = await remoteFetchAsync(link, {
            headers: {
                Authorization: `Bearer ${token}`
            }
        })
        let file = await response.json();
        let datetime = file["data"]["created_at"];
        let t_location = datetime.indexOf("T");
        let time = datetime.slice(t_location+1,t_location+9);
        console.log(time);
        
        await ranking.updateRecordAsync(line, {"tweet_time": `${time} GMT`});
        console.log("time updated");
        
    }
}

I would like to change it so it gets the time from each cell (tweet_time column) and then I can modify the if statement to only make it run when the cell was modified in the last 10 min (for example).

Thanks a lot!
Edouard

1 Reply 1

Hi @Edouard_Verstraete ! Unfortunately the scripting API doesn’t directly let you query the last modified time of a record or field value. The best that you can do is create a last modified time field that only returns the last modified time of your {tweet_time} field. You could then update your script to query that last modified time field.