Learn to use dynamic variables like $CURRENT_USER, $CURRENT_ROLE, and $NOW to create personalized views and time-based queries both in the app interface and API calls.
Speaker 0: Alright. Welcome back to another episode of Short Hops. I'm your host, Brian Gillespie. In this episode, we are talking about your friends who make filtering easier, dynamic variables. Dynamic variables, you can use these in any API calls when you are doing some filtering.
You can also use these inside the app. And I'll show you a couple of quick use cases for them. But we'll just run through the most popular ones. These are the main ones. We have dollar sign current underscore user.
That will give you the current ID of a particular logged in user. Current role will give you the current role ID of a logged in user, of the current logged in user. And then we have dollar sign now which will give you the current timestamp and you can do adjustments with this as well like now minus 1 year, now plus 2 hours. And I'll I'll show you how to get the most out of these in the application here. Alright, so let's take a look at a specific scenario.
I'm inside a sample app. I've got a contacts table here. Some of these would be assigned to me, some of them would not be. But if I take a look at it, just a a standard kind of CRM format. So now if I wanted to take a look at all of my contacts, and maybe what I want to do is put a bookmark in that every user has access to, a global bookmark.
But it's dynamic in that when they click on it, it shows their specific contacts. So the bookmark is is globally available, but it is filtered based on the current user. So how can we do something like that? Right? I can go in and I'm gonna set a filter here, let's say user created equals dollar sign underscore current user.
And now, I get a list of my specific contacts or the ones that I created. Right? You know, I could also, you know, have the owner of my organization as well. So if the owner of the organization equals current user, that is my list. Right?
And now I can go in and actually bookmark this and I may call it something like my contacts, because we can make this globally available. Great. So that is one way to use this. Let's take the scenario where I want to, you know, show me all the posts that have been published within the last month. Right, so again, I can use those dynamic variables to make filtering easier because I, you know, I don't wanna do the math and figure out what it was a month ago.
So I'm just gonna go in, date published is greater than and we'll do dollar sign now minus 1 month. And boom we could see that. And again, these same filters you can use within the API as well. So if I just pull up just a little API tool called Bruno that I've been using. And we are calling these posts.
So if we just get the post resource, we could see we're getting all of our posts here. This is just items slash posts. Now if I add a param for the date published, and let's do gt or underscore gt, which is greater than. And we'll do that dollar sign now. We'll do that same kind of query that we used.
1 month. And here you could see I'm only getting like 1 or 2 posts. Or if I wanted to see everything that's published within the last day, boom. So that's how this works. That is dynamic variables.
A lot you can do with these. So make sure you check them out. Read up on the documentation. And we'll see you in the next episode.