showNotification not working from inside handler script?

I have a short script attached to a button click handler that needs to display a notification. For some reason I don't see the notification window pop up, though I can log the same message to the console fine. The query below is a SELECT COUNT(*)... query.

What's wrong?

var Cnt;
await qryCountSubregions.trigger();
Cnt =[0];

if(Cnt > 0)
utils.showNotification("Region could not be deleted","The selected region's "+Cnt+" subregion(s) must first be deleted.","error" );
console.log("The selected region's "+Cnt+" subregion(s) must first be deleted.")
await qryRegionDelete.trigger();
utils.showNotification("Deletion confirmed","The highlighted record was deleted.","success");
console.log("The highlighted record was deleted.");

make sure Cnt is rendering as a number not a string.... maybe use int instead of var?

Thanks, ScottR.

Cnt seems to hold the correct numeric value, because the log message is correct:

The selected region's 1 subregion(s) must first be deleted.

But feeding the exact same message content to the showNotification does not show a notification box. That's what's weird.

I modified the script to explicitly make Cnt a number in the declaration, but still no joy.

 var Cnt = 0;

Still puzzled.....

i've noticed that notifications don't always show when you're in edit mode and you've been entering & exiting preview mode. this has been a longstanding bug/idiosyncrasy in my experience.

if you reload the page, and proceed immediately to the action that causes the notification, does it show?

Alas, no. I can live with it in this particular context - just displaying a label with the same message - but it's going to be a problem elsewhere, I have a feeling. Guess we'll cross that bridge when we come to it.

I should've looked closer at your posted code; I believe it has to conform to the function's object argument format to work, i.e. it won't infer based on argument ordering what is what.


  title: "Example title",
  description: "Example description.",
  notificationType: "success",
  duration: 3,

You don't need to supply all the keys, though.

utils.showNotification() docs


That was exactly it. Still hacking my way through JS.

Thank you!


Ahhhhh I should have looked closer :eyes:

Hey, I should have looked closer - at the documentation! :upside_down_face: