Play song when have new item in the list

Hello I want to do when I have a new item in my list … automatically play to song … how can I do this? i am using firebase …

Hi Rodrigo, check out the Play audio flow function from the marketplace → Documentation

Hi… Yes, I was looking at it, but how can I know that there is a new item in the list? thanks

Hi, that depends, how are items added to the list? :slight_smile:

I have it configured with firebase. When the order changes status, they appear in a list of pending orders. I would like that when an order is updated and pending, to activate an alert sound. What would be the best way to do it?

Hi, if your list is in a data variable, you could use the Receive event node and choose “Data (your data resource) changed” as the event source, and then Play audio after that.

Yes I tried doing it like this but it didn’t work. Since it is updated by delay.
should I take out delay?

Oh, you’re right. The delay is needed for the list to keep refreshing on the page, so maybe that’s not the best idea. :thinking:

You could create some additional logic:

  1. one number page variable that holds the previousLength of the pending list, initial value -1
  2. another number page variable that holds the currentLength, initial value -1
  3. a third number page variable newItems, that only changes if currentLength is more than previousLength → a new item has been added, initial value 0

As a flow:

What happens is:

  1. When the data variable is set, we first check if it’s the first time that the flow is executing (no value for previousLength yet). If so, then we set both previousLength and currentLength to COUNT(data.PendingItems) (length of the list). Otherwise we just set currentLength to COUNT(data.PendingItems.
  2. Then we check if the list has grown, with currentLength - previousLength === 1 (this will be -1 if some items have been removed from the pending list, we don’t want to get an alert then)
  3. If there is a new item, change the value of newItems to newItems + 1 with a formula, and in any case, set the page variable previousLength to the currentLength so the checking works correctly on the next run.

With this kind of setup you should then be able to use “Page variable newItems changed” as the trigger event for your sound, because it only changes in the event that your list has grown. :slight_smile:

1 Like

Thanks, I’m going to try it

yes it’s works Mari, but as I use firebase. sends the alert when a new order is created, not when the status changes to pending. How could it be filtered only when it changes state?
this is an item from the list: {
“name”: “projects / cafe-urquiza / databases / (default) / documents / Orders / 6SBruk7YcFNWocO3ZDSh”,
“fields”: {
“Pay with”: {
“stringValue”: “500”
“Total”: {
“stringValue”: “300”
“Condition”: {
“stringValue”: “Pending”
“Table”: {
“stringValue”: “Table1”
“createTime”: “2021-03-17T11: 56: 42.869395Z”,
“updateTime”: “2021-03-17T11: 57: 21.773434Z”

In that case you should look at the length of a list where only pending items have been filtered, you can get this with SELECT(list, item.Condition.stringValue === "Pending")

Thanks, but where should i apply that filter? I tried to apply it on previousLength and currentLength to COUNT(data.PendingItems) but it didn’t work

Just replace the formulas that reference the length of the whole items list with COUNT(SELECT(data.Items, item.Condition.stringValue === "Pending"), so you get the correct lengths :slight_smile:

I traid but it didn’t work. when i created new item is work but when I update an item it does not work. The idea I have is to count the number of items in the list that is filtered and if it changes to send the alert. But can the items of a list component be counted?

Hi, that’s exactly what SELECT(data.Items, item.Condition.stringValue === "Pending") should do – it makes a new list with only items that match the criteria, and then when you put COUNT() around that, it counts the number of items in that list. :thinking: Maybe you could try to check on the State tab in the debugger to see if some of the variables are not working as expected.

Thanks. You’re right…

1 Like