Reload or Refresh

I have an import function that works great, however I can't seem to find where I should add code to refresh the page. I've tried several places in my code, however none seem to work.

 

Thanks

 

Hi 367978297211

Thank you for the "location.hash = location.hash + "#" " code. 

I've been searching far and wide for code that would enable me to refresh the same scene that a form is located on. Reloading the whole page was causing an issue, as it was forcing users to log in again. And it caused an even bigger issue where we have an app embedded in another app.

This works perfectly, as it refreshes the whole scene, and as a result also applies the Page Rules again for that scene. My code snippet below that displays an alert, and refreshes the scene after the delay specified:

$(document).on('knack-record-update.view_2855', function(event, view, data) {

setTimeout(function () { location.hash = location.hash + "#"; }, 12000);

alert("Please wait while we fetch the Invoice from Autoline. Click 'OK' & this page will refresh in a few moments...");

Knack.showSpinner();

});

Thank you!

Hi Martin, you may need to look at finding the correct javascript trigger, but here is what we use in the API& Code section in the builder under Javascript

 

// does a quick refresh on the store add line item order screen
$(document).on('knack-record-create.view_901', function(event, view, record) {
location.hash = location.hash + "#"
});

 

You'll need to find your view number (instead of view_901) and you'll need to work out with your input what is the trigger. In my example we are tracking knack-record-create

We find the location.hash = location.hash + "#" works really well as it doesn't refresh the entire page and does its refresh very quickly.

 

I hope this helps a little!

Cheers

 

 

 

Is it possible to use this code to automatically refresh a page when a user lands on it? What I need is to ensure that my app users are getting the most up-to-date version of the app, therefore I need to force a page refresh as soon as they log in. Would your code work and are there any changes for my specific use case?

Hi @PeterBurto32327

You can use location.hash or location.reload() but you may have an infinite loop because the page reloading will probably trigger it again to reload. So instead, I would use one of the methods provided by the global Knack object.

For example:
Knack.views[view.key].model.fetch()
Knack.views[view.key].render()

The method depends on the view type (for example, table, details, etc).

I’d be happy to learn more about your use-case. You can schedule a time here.

Thanks,
Ian
Knack Pros