Conditionally show popup on page load?

I’m working on trying to conditionally show some alerts to users and have run into a snag. My goal is to check for related records for an account on page load and if there are any records, show a popup immediately that contains the records. There does not seem to be…

  • A way to initialize a popup on page load (without javascript)
  • A way to conditionally show a popup only if there are records (even within the action framework)
Am I overlooking some built-in features (especially with the banzai release) that would let me do this? Or do I need to use javascript to accomplish this.

Jonathan, I think a combination of Model Actions, Conditional Rendering, and Ui-Only Fields will get you where you’d like to be here.

I would start by creating a “Ui Only Model” on your page, basically just create a Model called something like “UiOnly” on the Account object, set to “Create Default Row if Model has None” and NOT Load records when page is first loaded. Then add a Ui-Only field to this Model called “PopupTrigger” or something like that, type of Picklist. Add a single Picklist Entry to this Ui-Only picklist field, with value “yes”. Now add a Model Action to your “Ui Only” Model. Initiating Events should be “Row in Model Updated”, Fields should be “PopupTrigger” only. Then for Actions, add a single Action: Show Popup. Here, show your table(s) of related records.

So now basically you’ve got a Popup that you can show on demand — all you have to do is to make any change the “PopupTrigger” field on your Ui Only Model’s one row.

At this point you need to cause an update to this field on page load — to do this, I would add a very small bit of Inline JavaScript that checks for records in your Related Record Models, and if so calls updateRow() to cause the update. I have experimented with other approaches that don’t involve JavaScript (using Conditional Rendering on a Field Editor on the Ui-Only Model with the PopupTrigger field in it, marked as Required), but I’m recommending not to go this route.

Here’s a sample page XML (note: this is assuming you are using Banzai):

UiOnly row.updated PopupTrigger {{Name}}: Popup should show on page load if there are related Contact or Case records Account Contacts Cases (function(skuid){ var $ = skuid.$;

$(document.body).one(‘pageload’,function(){

// CHANGE THESE MODEL IDS ONLY
var MODEL_IDS_TO_CHECK = [
‘Contacts’,
‘Cases’
];

var showPopup = false;

$.each(MODEL_IDS_TO_CHECK,function(i,modelId){
var model = skuid.$M(modelId);
if (model && model.getRows().length) {
showPopup = true;
return false;
}
});

if (showPopup) {
// Update our Ui-only model, this will cause our popup to be shown
skuid.$M(‘UiOnly’).updateRow(skuid.$M(‘UiOnly’).getFirstRow(),“PopupTrigger”,“yes”);
}
});

})(skuid);





Zach, I finally had a chance to play around a bit with your example and it seems to do the trick! I’ll definitely use this to handle my current situation. Thanks for the help!