Making SuiteCommerce Wait for Data Before a Page Loads

in , , August 29th, 2024
person using computer keyboard

There are a few reasons why you may want your SuiteCommerce site to wait for data from NetSuite before a page loads, including:

  • The page being loaded is displaying data you wish to be present immediately so there is not a delayed re-render.
  • The content to be displayed depends on a response from the server.
  • An error would get thrown without the data

There are two methods to make the site wait for your data.

Method 1: Wait for data no matter where the user is on the site

It is often the case that you want to wait for certain data to be fetched from NetSuite before anything loads. The site natively does this with things like the environment object and user object. Adding this to your extension is quite easy.

In your JavaScript entry point, you simply need to add a Promise object to the “container”. This is done using the code below:

mountToApp: function mountToApp(container) {
					
	let model = new SomeModel();
	
	let promise = model.save({
		email: crrUserMail
	});
	
	container.waitForPromise(promise);
	
	promise.done((res) => {})

or

mountToApp: function mountToApp(container) {		
	
	let promise = jQuerry.Deferred();
	
	container.waitForPromise(promise);
	
	promise.resolve();

The basics are as follows:

Step 1: Define some Promise object

Step 2: Either a generic one (jQuerry.Deferred()) or one based on a Backbone model call (i.e, “model.save”).

Step 3: Add that promise to the “container” object using the “waitForPromise" function.

Step 4: Resolve that promise when you need to.

The site will always wait for the promise to resolve to finish loading.

Method 2: Wait for data on a specific page(url)

It is often the case that you want to wait for certain data to be fetched from NetSuite before loading a page. Similar to above, this is quite easy.

The view rending on the page MUST have been created using the “registerPageType" function of the “PageType” component.

These views have a native function called “beforeShowContent". This function MUST return a Promise object. The view will wait for the promise to resolve before rendering.

Author: Sam Gagliardi


Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!


Oracle NetSuite Alliance Partner & Commerce Partner

If you have general questions about SuiteCommerce or more specific questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

We are a premium SuiteCommerce agency that creates powerful customer portals. Unlike our competitors, we have already solved your problems.

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart