What is the "real" document ID?

If you read the output of either the craft.dataApi.getCurrentPage() or
craft.editorApi.getSelection() commands, the value of the documentId property is not what is used to open the document via a URL link, such as:

craftdocs://open?blockId=2DE4A54D-77BA-4345-B138-1061193FA231&spaceId=ce67658f-fb37-d4e3-9525-1572c7fa708b

Instead, you must use the value of the outer wrapper Id as shown in this illustration.

Q: Is the value (highlighted in green) the “page ID” or the “real document ID”?

FYI, i’m using this extension to read the JSON to the OmniFocus console:
https://omni-automation.com/craft/omnifocus-log-craft-data.html

I’ve examined the JSON output from each page of a multi-page document and each page has a unique “outer Id” value, but they all share the same value for the “documentId” property.

Therefore, it appears that:

  1. the “outer Id” value is the page ID
  2. There is no URL syntax for opening a document using the value of “documentId” property.

Craft team: are those assumptions correct?

The outer ID is the rootblock id of the document, that is why that works :slight_smile:

The documentId is not used in the URL scheme, as the block navigation deeplink already handles that use-case using this rootblock id.

Think about documents as the wrapping object above the root node in a hierarchy of blocks. There are some blocks that are wrapped in a document object so they show up as documents within the app.

1 Like

Is that correct? If the outer ID is the rootblock of the DOCUMENT then wouldn’t it be the same for each page of the document? Currently each page of a multi-page document has a different “rootblock”. How does an eXtension programmatically retrieve the DOCUMENT rootblock when the eXtension is called while a secondary page is currently visible?

Thanks!

Here is the result of using the getCurrentPage() command on both the main page of multi-page document and the secondary page. As is shown, the value of the ID property is not the same. The value of the ID property is essentially the page ID.

Q: How does an eXtension programmatically retrieve the document’s rootblock when it is called from a secondary page?

// MAIN PAGE OF CRAFT DOCUMENT

{
  "hasFocusDecoration": false,
  "indentationLevel": 0,
  "listStyle": {
    "type": "none"
  },
  "spaceId": "859c432e-33f3-7983-7c20-67a12bd618aa",
  "style": {
    "fontStyle": "system",
    "alignmentStyle": "left",
    "textStyle": "page"
  },
  "documentId": "8CB89640-B2F5-4C7E-9F0D-0627EF2FA9D6",
  "color": "text",
  "content": [
    {
      "isItalic": false,
      "isStrikethrough": false,
      "text": "Main Page of Mutli-Page Document",
      "isCode": false,
      "isBold": false
    }
  ],
  "subblocks": [
    {
      "hasBlockDecoration": false,
      "id": "FA6D2781-5D72-4EDC-83B4-F02394463812",
      "style": {
        "fontStyle": "system",
        "alignmentStyle": "left",
        "textStyle": "body"
      },
      "hasFocusDecoration": false,
      "documentId": "8CB89640-B2F5-4C7E-9F0D-0627EF2FA9D6",
      "listStyle": {
        "type": "none"
      },
      "subblocks": [],
      "type": "textBlock",
      "color": "text",
      "indentationLevel": 0,
      "spaceId": "859c432e-33f3-7983-7c20-67a12bd618aa",
      "content": [
        {
          "isItalic": false,
          "isStrikethrough": false,
          "text": "This is the main page of a multi-page document.",
          "isCode": false,
          "isBold": false
        }
      ]
    },
    {
      "hasBlockDecoration": false,
      "id": "8D595FDD-4055-4B8C-AE24-2AB2D4230871",
      "style": {
        "fontStyle": "system",
        "alignmentStyle": "left",
        "textStyle": "page"
      },
      "hasFocusDecoration": false,
      "documentId": "8CB89640-B2F5-4C7E-9F0D-0627EF2FA9D6",
      "listStyle": {
        "type": "none"
      },
      "subblocks": [
        {
          "hasBlockDecoration": false,
          "id": "DF5A4293-58FB-40A5-97D9-D6DDEA107723",
          "style": {
            "fontStyle": "system",
            "alignmentStyle": "left",
            "textStyle": "body"
          },
          "hasFocusDecoration": false,
          "documentId": "8CB89640-B2F5-4C7E-9F0D-0627EF2FA9D6",
          "listStyle": {
            "type": "none"
          },
          "subblocks": [],
          "type": "textBlock",
          "color": "text",
          "indentationLevel": 0,
          "spaceId": "859c432e-33f3-7983-7c20-67a12bd618aa",
          "content": [
            {
              "isItalic": false,
              "isStrikethrough": false,
              "text": "This is the secondary page of the document.",
              "isCode": false,
              "isBold": false
            }
          ]
        }
      ],
      "type": "textBlock",
      "color": "text",
      "indentationLevel": 0,
      "spaceId": "859c432e-33f3-7983-7c20-67a12bd618aa",
      "content": [
        {
          "isItalic": false,
          "isStrikethrough": false,
          "text": "This is the link to a secondary page of the document.",
          "isCode": false,
          "isBold": false
        }
      ]
    }
  ],
  "hasBlockDecoration": false,
  "type": "textBlock",
  "id": "DC672BD1-554F-4684-AB2A-FF974606943A"
}
// SECONDARY PAGE OF CRAFT DOCUMENT 

{
  "color": "text",
  "content": [
    {
      "isItalic": false,
      "isStrikethrough": false,
      "text": "This is the link to a secondary page of the document.",
      "isCode": false,
      "isBold": false
    }
  ],
  "hasFocusDecoration": false,
  "documentId": "8CB89640-B2F5-4C7E-9F0D-0627EF2FA9D6",
  "spaceId": "859c432e-33f3-7983-7c20-67a12bd618aa",
  "type": "textBlock",
  "listStyle": {
    "type": "none"
  },
  "indentationLevel": 0,
  "subblocks": [
    {
      "hasBlockDecoration": false,
      "id": "DF5A4293-58FB-40A5-97D9-D6DDEA107723",
      "style": {
        "fontStyle": "system",
        "alignmentStyle": "left",
        "textStyle": "body"
      },
      "hasFocusDecoration": false,
      "documentId": "8CB89640-B2F5-4C7E-9F0D-0627EF2FA9D6",
      "listStyle": {
        "type": "none"
      },
      "subblocks": [],
      "type": "textBlock",
      "color": "text",
      "indentationLevel": 0,
      "spaceId": "859c432e-33f3-7983-7c20-67a12bd618aa",
      "content": [
        {
          "isItalic": false,
          "isStrikethrough": false,
          "text": "This is the secondary page of the document.",
          "isCode": false,
          "isBold": false
        }
      ]
    }
  ],
  "style": {
    "fontStyle": "system",
    "alignmentStyle": "left",
    "textStyle": "page"
  },
  "id": "8D595FDD-4055-4B8C-AE24-2AB2D4230871",
  "hasBlockDecoration": false
}

Note however, that the value of the “documentId” property IS the same on each page. It would be very useful if the value of the “documentId” property could be used in a URL to display a Craft document.

Sorry, I was assuming you are fetching the data on the outermost page (root page). if you are inside a page, it will be the current page id that is open.

LOL! Yup, describing the issue sometimes is more challenging than solving it!

The basic concept I’m trying to solve is programmatically linking external resources to a “document” rather than a “page” or “block” that may be ultimately deleted. If you have ideas, please let me know!

Cheers.