Pick Random row from Google Sheets

How to pick a random row from Google Sheets using Sheets Node?

Hi @mcnaveen, one of the ways to accomplish this would be to add a Function node in front of the Google Sheets node and add JavaScript code which can make that happen. The code for the Function node could look something like this:

const newItems = [];

random_row = items[Math.floor(Math.random() * Math.floor(items.length))];
newItems.push(random_row);

return newItems;

Please note that using this code in the Function node will only return one random row out of the list of the rows returned by the Google Sheets node. Hope that helps! :slight_smile:

2 Likes

Worked after adding a Function node next to Google Sheet. Thanks, @tanay for your quick response

image

Great to hear that helped. Have fun! :slight_smile:

1 Like