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 = argumentsm0],
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;
weekUpdateModel.updateRow(weekUpdate,‘Note’,userAlias);
$.each(weekUpdateModel.registeredItems,function(){
this.refreshFields();
});
Thanks,
Jacob
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.
Thanks Rob! Learning JS by sheer force is challenging sometimes.
Page loading snippet
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!
Check out J’s discussion here: https://community.skuid.com/t/page-include-inline-javascript-not-running-has-anyone-do…
(function(skuid) { <br> var $ = skuid.$;<br> // Register a snippet to run<br> skuid.snippet.registerSnippet('HelloWorld', function() {<br> console.log("Go Skuid!");<br> });<br> // Called on page load<br> function init() {<br> skuid.snippet.getSnippet('HelloWorld')();<br> }<br> // Run the snippet initially on page load<br> $('.nx-page').one('pageload', function() {<br> init();<br> });<br>})(skuid);
Thanks! Found the solution
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.