Table of Contents

The App / Module Sxc Instance

you are here (click to zoom) - discover the stack

The module-specific sxc-instance is the core JavaScript object helping you in these cases:

  1. if you want full control over the edit-experience with custom buttons etc.
  2. when you want to use view-data as an asyc-JS call
  3. if you wish to work with WebAPI REST calls - of your own App-WebApi, 2sxc-WebApi or Dnn-WebApi

How to use

First you must ensure that you have the $2sxc global on your page, which will get you a module-specific sxc.

Here's a simple example (assuming you have the $2sxc global):

<a onclick="var sxc = $2sxc(this); alert(sxc.isEditMode())">
    click me 
</a>

The code above shows

  1. how the sxc-object is retrieved using the $2sxc(...) global, based on the current context this
  2. how to ask if we're in edit-mode

Here's another quick example, calling a C# web-api endpoint:

var sxc = $2sxc(27);
sxc.webApi.post("Form/ProcessForm")
    .success(function(result) {
        // ....
    });

How to Get the Current Context's sxc Instance

Before you continue, make sure you know how to resolve/get your sxc, as it is unique for each Dnn-Module. This is because each action needs to know which module it belongs to. Read about the 3 ways to get this in the $2sxc Global docs.

The API of an Module sxc Instance

📖 Sxc

Common Tasks

  1. Work with the JSON Data of the Current Module
    📖 In v.13+ you should should use the Data Service
  2. Work with REST Api to Read/Write Content-Items / Data
    📖 In v.13+ you should should use the Data Service
    In older versions, use the Sxc WebApi
  3. Use App-Queries with $2sxc
    📖 In v.13+ you should should use the Query Service objects.
    In older versions, use the Sxc WebApi
  4. Work with Custom C# App WebAPIs
    📖 Read about it in the Sxc WebApi page.

You should find some code examples in this demo App

More links: Description of the feature on 2sxc docs

History

  1. Introduced in 2sxc 04.00
  2. Enhanced with SxcData and SxcQuery in 2sxc 13.00