Show a notification on page load if a record has a certain value

Hi everyone

I have a dashboard which a logged in user sees and there’s a list of records (created using the BS4 generator) and one of the columns is whether it’s active or not. I want to show a notification on page load if any of the records is not active.

I’ve created the notification component but can’t work out how I set it to show. Could someone give me a steer?

Many thanks.

I suppose you are getting the list of records from a server connect.
On the on-success event of this SC, check if the returned records contain any records where isactive field is 0 (assuming that is how you identify an inactive record).
This part can be done visually using the where option on the SC’s data part.

Next part would be to show the notification, which can again be done visually, using tue notify property.

Once you have both those parts, to make it a condition, you will need to do it in the code view, using a ternary operator.
It would look something like:
dmx-onsuccess="screcords.data.where(isactive, ==, 0).hasItems() ? notification1.notify('inactive record found') : ''"

If you don’t want anything in the else part, make sure to put empty quotes.

Thanks for the steer, @sid. You highlighted something I’d overlooked and so I’ve actually managed to do it without any hand coding.

I’d already created the server action which had a query on it to get only the records which were not active. I’d also created the notification component which had the show dynamic attribute and the ‘has items’ data format.

Then the bit I was missing which your reply steered me to was the ‘Ready’ dynamic event on the body tag which showed the notification.

And now it works to only show the notification when the query has items.

I am trying to build the entire site without any hard coding so am pleased to get this part working.

Thanks again for your tip.

Glad to hear it all worked out.

Although, instead of using the ready event, I would still suggest to use on-success of the server connect as it will be more accurate.
Correct me if I’m wrong, but I don’t think the ready event waits for the server connects on the page to get loaded… so until server connect completes, you will not have the actual state.

You will have to go into the code view to use on-success, but I think it is a fair trade off for a better UX. Until conditionals get added to the visual picker.

I’ll look further into that. My tests seem to be delivering it perfectly, though.