Class SxcData
Data Service for an App / Sxc-Instance to get/create data of a specific Content-Type
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Package: Api.Js.SxcJs
Properties
name
Data Service for an App / Sxc-Instance to get/create data of a specific Content-Type
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
name: string
Property Value
Type | Description |
---|---|
string |
Methods
create(Record<string, unknown>)
Create a new entity with the values supplied
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function create(values: Record<string, unknown>)
Parameters
Type | Name | Description |
---|---|---|
Record<string, unknown> | values |
a simple object containing the values to create |
Returns
Type | Description |
---|---|
Promise<Record<string, unknown>> |
create(Record<string, unknown>, MetadataFor | string)
Create a new entity with the values supplied and also a metadata-for reference
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function create(values: Record<string, unknown>, metadataFor: MetadataFor | string)
Parameters
Type | Name | Description |
---|---|---|
Record<string, unknown> | values |
a simple object containing the values to create |
MetadataFor | string | metadataFor |
Returns
Type | Description |
---|---|
Promise<Record<string, unknown>> |
delete(number)
Delete an entity
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function delete(id: number)
Parameters
Type | Name | Description |
---|---|---|
number | id |
id of the item to delete |
Returns
Type | Description |
---|---|
Promise<null> |
delete(string)
Delete an entity
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function delete(guid: string)
Parameters
Type | Name | Description |
---|---|---|
string | guid |
GUID of the item to delete |
Returns
Type | Description |
---|---|
Promise<null> |
getAll()
Get all items of this type.
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function getAll()
Returns
Type | Description |
---|---|
Promise<T[]> |
getOne(number)
Get the specific item with the ID. It will return null if not found
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function getOne(id: number)
Parameters
Type | Name | Description |
---|---|---|
number | id |
Returns
Type | Description |
---|---|
Promise<T> | null |
update(number, Record<string, unknown>)
Update an existing entity with the values supplied
sxc.data
Services of the Sxc Instance
A common need in JS is to read/write data from/to the backend.
2sxc 13 introduce new JS APIs for this.
data(...)
gets a data service to get one or many items of the same type, and also create/update data (this document)query(...)
gets a query service to call server-side queries 👉 docs
Note: You can do all what these services do using webApi.fetchJson(...), but this is more convenient.
Tip
You may sometimes find old code which does something like data.on(...)
or data.sourceUrl
- this is obsolete and will not work any more.
👉 Check out the Js Data and Query Tutorials
Tip
The data format is described here: JSON Data Format used in WebAPI calls (technical)
Get a Data Service
- Get the Sxc Instance of the current module
- Call
.data(contentTypeName)
to get the service
Example:
const modId = @CmsContext.Module.Id;
const sxc = $2sxc(modId);
const authorsSvc = sxc.data('Authors');
authorsSvc.getAll().then(authors => console.log(authors));
Data Service Factory Parameters
The data(...)
factory just has one parameter: the contentTypeName
.
The returned service will always perform actions for this content-type.
Data Service APIs
Data Services always return a modern Promise containing data.
A Data Service has the following commands:
getAll()
- no parameters, will return an array of all items of this content-typegetOne(id)
-id
is an int - will return a single item of this content-typecreate(objectWithValues)
-objectWithValues
is a JS object with keys/values - will create the item and return itcreate(objectWithValues, metadataFor)
-metadataFor
creates an item as metadata for somethingdelete(id)
WIPdelete(guid)
WIPupdate(id, objectWithValues)
- performs an update on the targeted item and returns the item. Note that objectWithValues can also just have a few properties, all others will be left as is.
Create Metadata
When using create(..., ...)
with two parameters you are creating metadata. The signature of the address-object is
- Either a string containing a GUID to an entity (the most common case) - like
31f509f1-e553-4371-bf60-3d5e98937b79
- Or a full target identifier with TargetType and the ID as String, Number or Guid - see JSON Data Format used in WebAPI calls (technical)
Tutorial
Declaration
function update(id: number, values: Record<string, unknown>)
Parameters
Type | Name | Description |
---|---|---|
number | id | |
Record<string, unknown> | values |
Returns
Type | Description |
---|---|
Promise<Record<string, unknown>> |