setActivityJson - Methods - Author API

Author API Methods

setActivityJson()

Sets the Activity data (the content of the data property) for the Activity being edited.

You would want to use this method so that you can programmatically set default values for various settings and content for the current Activity, for example.

Examples

// Merge mode (default) - extends existing data
var result = authorApp.setActivityJson({
    "items": [
        {
            reference: "test1",
            organisation_id: 1
        },
        {
            reference: "test3",
            organisation_id: 1,
            item_pool_id: "pool_1"
        }
    ],
    "config": {
        "time_limit": 300
    }
});

// Replace mode - completely replaces activity data
var result = authorApp.setActivityJson({
    "items": ["item1", "item2"],
    "rendering_type": "inline",
    "config": {
        "shuffle_items": true
    }
}, { extend: false });

Arguments

  • activityData activityJson

    The new Activity data object in JSON format. This is the content of the data property, not the full Activity structure. See Type definitions for more information.

  • options object

    Options for customizing the behavior of the setActivityJson() method.

    The following properties are supported.

    • extend boolean

      Controls whether the supplied Activity data is merged with or replaces the existing Activity data.

      Default: true

      Possible values

      • true - The supplied Activity data is merged with the existing Activity data. Existing fields are preserved, and new fields are added.
      • false - The supplied Activity data completely replaces the existing Activity data.

Return value

Type boolean

Returns true if successful.

Returns false if unable to set the Activity data. For example, when not in the Activity editor view, when the Activity is read-only, or when called from item edit within Activity edit.

Type definitions

  • activityJson object

    Definition of the Activity JSON.

    The following properties are supported.

    • config object

      The Items API initialization options. See the Items API initialization options for more information.

    • items array[ItemObject]

      An array of ItemObject references to be used in the Activity.

    • rendering_type string

      The Items API rendering type for the assessment, which can be rendered inline or using the assessment player.

Versioning

Version added: v2026.2.LTS (now live in developer)

Related articles

  • The getActivity() allows you to retrieve the full Activity object, including reference, title, tags, and the data property.
  • The setActivity() is deprecated and has been replaced by setActivityJson().
Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.