Can't get snippet to run on page load

edited May 19, 2019 in Questions
Mostly because I don't know how :)

I have a script which works fine when pasted into the console, but I would like for it to run on Page Load.

var params = arguments[0],

    step = params.step,

$ = skuid.$;

var userModel = skuid.model.getModel('User'),
    user = userModel.getFirstRow(),
   weekUpdateModel = skuid.model.getModel('WeeklyUpdate'),
   weekUpdate = weekUpdateModel.getFirstRow();
var userAlias = user.Alias + ' Update - ' + user.Today__c;




  • Rob Hatch
    Rob Hatch 🛠️ 
    edited September 1, 2016
    You actually want this snippet to run AFTER page load,  because you need the model data to be available.  This is why it runs successfully from the console.  Models have loaded etc.  You need to wrap your snippet in a function that waits for the page to load before executing.  Somthing like this: 
    (function(skuid){    var $ = skuid.$;    $(function(){       Your Function goes here......    }); })(skuid);
    Actually if you create a new Javascript resource of type Inline you will get this code prepopulated for you.  
  • j_flatter
    edited April 9, 2014
    Thanks Rob! Learning JS by sheer force is challenging sometimes.
  • Gary Bailey
    edited November 28, 2017
    Page loading snippet
  • Sharon Anoop
    edited August 19, 2015
    Hi Rob, This works fine for a page. But when i use this page as a popup in another, its not working. Can u please suggest a solution for it? Thanks!
  • Irvin Waldman
    edited May 8, 2019
    (function(skuid) {    
        var $ = skuid.$;
        // Register a snippet to run
        skuid.snippet.registerSnippet('HelloWorld', function() {
            console.log("Go Skuid!");
        // Called on page load
        function init() {
        // Run the snippet initially on page load
        $('.nx-page').one('pageload', function() {
  • Sharon Anoop
    edited August 19, 2015
    Thanks! Found the solution :)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!