Skip to content

[QUERY] Problem storing an object containing an array to a datastore #250

Description

@markfoden

I am having a problem storing an object containing an array to a datastore.

Below I've posted:

  • The datastore type definition
  • The essential parts of the function that creates the datastore item
  • Output from "slack datastore get" after creating the item

My test item saves to the datastore but the "partner_names" array is empty and (in the datastore get output) seems to be showing as an object rather than an array

I see from https://api.slack.com/automation/types/custom#define-type that arrays within objects need to be defined. I think I've done that and now I'm stuck.

Can you help please?

Mark

TYPE DEFINITION

export const ArrayOfNames = DefineType({
    name: "ArrayOfNames",
    type: Schema.types.array,
    items: {type: Schema.types.string }
  });
  
  export const TestType  = DefineType({
    name: "TestType",
    type: Schema.types.object,
    properties: {
      deal_name: { type: Schema.types.string },
      partner_names: { type: ArrayOfNames }
  }});

  export default DefineDatastore({
    name: "test-data",
    primary_key: "id",
    attributes: {
      id: {
        type: Schema.types.string,
      },
      test_field: {
        type: TestType,
      },
  }});

FUNCTION

const testObject = {
    deal_name: "test name",
    partner_names: ["name1","name2"]
    };

const putResponse = await client.apps.datastore.put({
    datastore: "test-data",
    item: { 
    id: "1",
    test_field: testObject,
    }
});

OUTPUT

  {
    "id": "1",
    "test_field": {
      "deal_name": "test name",
      "partner_names": {}
    }
  }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendSlack backend issuebugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions