Update page load snippet

I use page load snippet very often to warn users of pertinent information on the page. In this example we want to warn users when they get to a Utility Account where the “Do Not Enroll” checkbox is checked. It looks something like this:

(function(skuid){ var $ = skuid.$;
var uaRow = skuid.model.getModel(‘UtilityAccount’).getFirstRow();
var pageTitle = $(‘#MyPageTitle’);
      var editor = pageTitle.data(‘object’).editor;
            editor.handleMessages([{message:‘Utility Account is set to “Do Not Enroll”’, severity:‘WARNING’}]);

It works great however in this exapmle if the user changes the checkbox to false, the page does not reflect that change and the warning stays at the top of the page until the user reloads. I understand that obviously it is a page load snippet and therefore is not dynamic, however… It would be great if there was a way to rerun it after an update to the field that it is based off of. Is there a way to have the page load snippet refresh itself? Maybe via a listener… ?

Hi Moshe,

What I would do is to re-factor your logic here into a Snippet. Then, you can have that Snippet run on page load, and you can have it triggered by Model events using Model Actions.

So here is my modified version of your Inline JavaScript code:

    var $ = skuid.$;
    // Register a snippet to run 
        var MODEL\_ID = 'UtilityAccount';
        var FIELD\_TO\_CHECK = 'Do\_Not\_Enroll\_\_c';
        var WARNING\_MESSAGE = 'Utility Account is set to "Do Not Enroll"';
        var proceed = true;
        if (changeInfo && changeInfo.updates) {
            // If the field we're looking at was not updated, 
            // then don't run our logic
            if (!(FIELD\_TO\_CHECK in changeInfo.updates)) {
        if (proceed) {
            var uaRow = skuid.model.getModel(MODEL\_ID).getFirstRow();
            var pageTitle = $('#MyPageTitle');
            var editor = pageTitle.data('object').editor;
                editor.handleMessages([{message:WARNING\_MESSAGE, severity:'WARNING'}]);
            } else {
    // Run the snippet initially on page load

This Inline JavaScript will run your snippet immediately on page load.

Then, to have it run every time a row in your Model is updated, add a Model Action on that Model, with Initiating Events: “Row in Model updated”, and the Action, “Run a JavaScript Snippet”, running the snippet “UtilityAccountEnrollmentWarning”.

The logic in the above JavaScript will cause your Snippet to be run whenever the Do_Not_Enroll__c field is changed.

Thanks Zach works great! I just had to add a “Model saved” initiating event as well but it does the job.