Init Callback
On this pageShowHide

Init Callback

HTML
<script>
  // in the initialization snippet, instead of SP.init("WEBSITE_ID");
  SP.init("WEBSITE_ID", function () {
    // the library is ready
    var client = SP.getClient();
  });
</script>

Make sure to replace WEBSITE_ID with your Website ID.

The second argument of SP.init() in the initialization snippet is a callback, called once the library is loaded and initialized.

Queued and direct calls

Until the library is loaded, the snippet only defines SP.init() and SP.go(). Calls made with SP.go() are queued and run, in order, as soon as the library is ready, so you can use them anywhere after the snippet:

JavaScript
SP.go('saveClient', { email: "CUSTOMER-EMAIL" });

Methods that return a value, like SP.getClient() or SP.getBasketValue(), can’t be queued: before the library is loaded there is nothing to return. Call them directly, inside the callback:

JavaScript
SP.init("WEBSITE_ID", function () {
  var basketValue = SP.getBasketValue();
});

See Client Data, Products and Basket for the methods you can call there.