MoreBeerMorePower

Power Platform中心だけど、ノーコード/ローコード系を書いてます。

How to add Static Data into your Power Apps (not Excel Table)

f:id:mofumofu_dance:20210226234125p:plain

Intro

The most common way to use static data in Power apps is to import Excel tables.

However, this data is static, but not protected, as it can be accidentally deleted by makers who can edit the app.

You've may already seen such static, protected data - it is the "CustomGallerySample" data that is initially set when you add a gallery control to the app:

f:id:mofumofu_dance:20210226214058p:plain

This data is static and protected and cannot be deleted by the app author.

In this post, I will show you how to add this kind of static custom data to Power Apps.

Static protected data in Power Apps

Unfortunately, it is not possible to insert static data from the UI, and you will need to manipulate the Power Apps source code files in order to achieve this.

Please refer to the following URL for the official announcement.

powerapps.microsoft.com

By following the steps in above announcement, unpack the appropriate app and view the folder containing the source code, you will find a file named "CustomGallerySample.json".

This corresponds to the source code of the static and protected data.

[Root directory]\DataSources\CustomGallerySample.json

f:id:mofumofu_dance:20210226214300p:plain

[
  {
    "Data": "[{\"SampleHeading\":\"Lorem ipsum 1\",\"SampleImage\":\"/ctrllib/image/images/SampleImage.svg\",\"SampleText\":\"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\"},{\"SampleHeading\":\"Lorem ipsum 2\",\"SampleImage\":\"/ctrllib/image/images/SampleImage.svg\",\"SampleText\":\"Suspendisse enim metus, tincidunt quis lobortis a, fringilla dignissim neque.\"},{\"SampleHeading\":\"Lorem ipsum 3\",\"SampleImage\":\"/ctrllib/image/images/SampleImage.svg\",\"SampleText\":\"Ut pharetra a dolor ac vehicula.\"},{\"SampleHeading\":\"Lorem ipsum 4\",\"SampleImage\":\"/ctrllib/image/images/SampleImage.svg\",\"SampleText\":\"Vestibulum dui felis, fringilla nec mi sed, tristique dictum nisi.\"}]",
    "IsSampleData": true,
    "IsWritable": false,
    "Name": "CustomGallerySample",
    "OrderedColumnNames": [
      "SampleImage",
      "SampleHeading",
      "SampleText"
    ],
    "OriginalName": "CustomGallerySample",
    "OriginalSchema": "*[SampleHeading:s, SampleImage:i, SampleText:s]",
    "Schema": "*[SampleHeading:s, SampleImage:i, SampleText:s]",
    "Type": "StaticDataSourceInfo"
  }
]

You can add your own defined static protected data to your app by copying this file and changing the settings. When creating data, the following changes should be made.

  • Data : string representation of a JSON Array.
  • Name : Data name
  • OrderedColumnNames : Column names included in your data.
  • OriginalName : Same as Name
  • OriginalSchema : Data schema (explained later)
  • Schema : Same as OriginalSchema

f:id:mofumofu_dance:20210226232312p:plain

As for the data schema, it is expressed in the following format:

 "*[ColumnName1:DataType1, ColumnName2:DataType2, ...]"

where DataType is a single character, depending on the data type of each column.

  • n : number
  • s : string
  • b : boolean
  • d : DateTime *
  • D : Date Only *

  • Unixtime in milisecond ( = integer)

Now all you need to do is to repack the source code and open msapp in Power Apps studio, and you will be able to use the static data that you have set up!!

Sample Data

Based on the above steps, I have added the following sample data to Power Apps. The result is shown in the figure, with the expected data type

[
    {
      "Data": "[{\"column1\":123,\"column2\":\"abc\",\"column3\":true,\"column4\":1614338477000,\"column5\":1614338477000},{\"column1\":234,\"column2\":\"def\",\"column3\":false,\"column4\":1614320000000,\"column5\":1614320000000},{\"column1\":345,\"column2\":\"fgh\",\"column3\":true,\"column4\":1614000000000,\"column5\":1614000000000}]",
      "IsSampleData": true,
      "IsWritable": false,
      "Name": "SampleStaticData",
      "OrderedColumnNames": [
        "column1",
        "column2",
        "column3",
        "column4",
        "column5"

      ],
      "OriginalName": "SampleStaticData",
      "OriginalSchema": "*[column1:n, column2:s, column3:b, column4:D ,column5:d]",
      "Schema": "*[column1:n, column2:s, column3:b, column4:D, column5:d]",
      "Type": "StaticDataSourceInfo"
    }
  ]

f:id:mofumofu_dance:20210226225707p:plain