# Create object

The Create object action node adds a new [object](/reference/platform-concepts/objects.md) in a [data source](/reference/apps/data/data-sources.md).

## Usage

This action node is used to create a new [object](/reference/platform-concepts/objects.md) with a set of properties defined by its [object class](/reference/data-model/object-classes.md). The object class is set on the [data source](/reference/apps/data/data-sources.md) that the object is created in.

To understand the differences in behavior when creating an object in a database-connected data source compared to a runtime-only data source, see [Database-connected and runtime-only data sources](/reference/apps/data/data-sources.md#database-connected-and-runtime-only-data-sources) under [Data sources](/reference/apps/data/data-sources.md).

When an object is created it is assigned an automatically-generated, globally unique identifier. This is stored in the **ID** property. The ID consists of 24 characters (letters and numbers) and will never change. For example, `605b5cdd5527f30cf344ab2a`.

{% hint style="info" %}
**Good to know**

Objects can also be created automatically in runtime-only, single-cardinality data sources by selecting **Auto Create** on the data source.
{% endhint %}

### Example

{% tabs %}
{% tab title="Create a new object with user data" %}
Your app is used to manage projects. You'd like for users to be able to add tasks to a project.

To do this, add a `Add task` button in the project detail view. Trigger an action when this button is clicked that runs Create object and adds a new `Task` object in a runtime-only single-cardinality data source. Use **Values on create** to set a `Project` property to the relevant project, connecting the task to the project.

Run an Open Dialog action node to display a [dialog](/reference/apps/ui/views/dialog.md) containing [input components](/library/ui-components.md#data-input) bound to other properties on the **Task** object that the user should set. Add a `Save` button to the dialog that triggers an action with a [Persist objects action node](/library/action-nodes/persist-objects.md) to save the new object to the database.

Note that the object needs to be created before the user can enter any data.
{% endtab %}
{% endtabs %}

#### Working with schemas

Create Object can target an [action variable](/reference/actions/action-variables.md) of type [schema](/reference/platform-concepts/schemas.md). When the target is a schema, the action node creates a new object in the schema structure and the **Values on create** section maps values onto the schema's properties.

To populate an array property in a schema, you can data bind it to a data source. The objects from the source are created as elements within the schema array. See an example setup in the image below.

<figure><img src="/files/2NQ8nr306aiUImD43n4V" alt=""><figcaption><p>Creating objects in an array using a databinding to a data source.</p></figcaption></figure>

When schema data needs to be written to the database, the property values from the schema can be mapped onto an [action data source](/reference/actions/action-data-sources.md) backed by an object class using **Values on create**. Only schemas with overlapping properties are shown as mapping candidates. Once the data is mapped onto the action data source, it can be persisted with the [Persist Objects](/library/action-nodes/persist-objects.md) action node.

There are a few behaviors specific to schemas:

* On an array-typed schema property, **Replace existing object** defaults to false. New objects are appended to the array rather than replacing its contents.
* On a cardinality-one schema, running Create Object a second time raises an error rather than silently replacing the existing object. Delete the existing object first if you need to replace it.
* Create Object is not available on primitive schema properties. Primitive values are created automatically when the parent object is created. Use the [update object](/library/action-nodes/update-object.md) action node to modify their value.

## Properties

<table><thead><tr><th width="236">Property</th><th>Description</th></tr></thead><tbody><tr><td><strong>Data Source</strong></td><td>Select a data source to create the object in.</td></tr><tr><td><strong>Replace Existing Object</strong></td><td><em>Available if</em> <strong>Data Source</strong> <em>is a runtime-only data source.</em><br><br>Remove any existing objects in the selected <strong>Data Source</strong> before the new object is created.</td></tr><tr><td><strong>Copies</strong></td><td><em>Available if</em> <strong>Data Source</strong> <em>is a runtime-only, many-cardinality data source.</em><br><br>Create multiple objects at once by setting the number of copies to create. All objects will have the same values as set under <strong>Values on create</strong> but each will have a unique <strong>ID</strong>.</td></tr><tr><td><strong>Set Selected</strong></td><td><em>Available if</em> <strong>Data Source</strong> <em>is a many-cardinality data source.</em><br><br>Set the newly created object as <a href="/spaces/-MiLU-xcHu0eLZiTxcmZ/pages/-MiR92uc7YpwXZWPxMI1#object-selection">selected</a>.</td></tr><tr><td><strong>Values on create</strong></td><td>Set values for any object class properties in the new object.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appfarm.io/library/action-nodes/create-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
