Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Post random Airtable search results to Slack?

1958 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Kevin_Purdy
4 - Data Explorer
4 - Data Explorer

I’ve got a pretty cool thing working, as a result of Airtable’s handy tutorial. In a Slack channel about video games at work, you can type “/gamerec,” followed by either the platform (Switch) or person recommending (Tim), it searches our collaborative Airtable spreadseheet of game recommendations, and then it kicks back 3 of those results to you, inside the Slack channel, all nice and pre-formatted. Yay!

But I want to make it better. I want you to get 3 random results from that search, so that it’s a bit more of a roulette wheel. If Tim has recommended 25 games, you shouldn’t get the same 3 games all the time.

Is there any way to alter the app so that the records returned are random? If not through Airtable’s API, do I have to do that within JavaScript, in the Node.js via Glitch app? Appreciate any help y’all can swing.

1 Reply 1

There’s currently no intrinsic random[ish] number generator within Airtable. There are ways of getting more-or-less unique, albeit non-random, values out of the platform, values that can be converted, through the application of various arbitrary numeric functions (think ’MOD() by a prime and the like), into something that looks relatively random if you squint hard enough. (Put it this way: I wouldn’t trust it as the seed for an encryption package, but it would probably be reliable enough for a utility that spits out video game recommendations.)

The problem then becomes how to use said kinda random value to determine which three of twenty-five results to return, given Airtable’s lack of array functions. You may find it’s better to return the entire set of, say, Tim-recommended games to your app and then use a pseudorandom generator built in Javascript or similar to determine which of the returned records are actually displayed.