0

I use the @pnp/sp library to get list data in a SPFX web part. The crucial code for my issue looks as follows:

const list = await sp.web.lists
      .getByTitle("ListTitle")
      .fields.getByTitle("Category")
      .get();
return list.Choices.results;

When I open the SharePoint page, where the web part is located, in view mode, it loads the correct object:

{
    "__metadata": {
        "id": "...",
        "uri": "...",
        "type": "SP.FieldChoice"
    },
    "DescriptionResource": {
        "__deferred": {
            "uri": "..."
        }
    },
    "TitleResource": {
        "__deferred": {
            "uri": "..."
        }
    },
    "AutoIndexed": false,
    "CanBeDeleted": true,
    "ClientSideComponentId": "00000000-0000-0000-0000-000000000000",
    "ClientSideComponentProperties": null,
    "ClientValidationFormula": null,
    "ClientValidationMessage": null,
    "CustomFormatter": null,
    "DefaultFormula": null,
    "DefaultValue": "SocialEvent",
    "Description": "",
    "Direction": "none",
    "EnforceUniqueValues": false,
    "EntityPropertyName": "...",
    "Filterable": true,
    "FromBaseType": false,
    "Group": "Benutzerdefinierte Spalten",
    "Hidden": false,
    "Id": "...",
    "Indexed": false,
    "IndexStatus": 0,
    "InternalName": "...",
    "IsModern": false,
    "JSLink": "clienttemplates.js",
    "PinnedToFiltersPane": false,
    "ReadOnlyField": false,
    "Required": true,
    "SchemaXml": "<Field Type=\"Choice\" DisplayName=\"Category\" Required=\"TRUE\" EnforceUniqueValues=\"FALSE\" Indexed=\"FALSE\" Format=\"Dropdown\" FillInChoice=\"FALSE\" ID=\"{...}\" SourceID=\"{{listid:...}}\" StaticName=\"...\" Name=\"...\" ColName=\"nvarchar4\" RowOrdinal=\"0\" CustomFormatter=\"\" Version=\"2\"><Default>SocialEvent</Default><CHOICES><CHOICE>SocialEvent</CHOICE><CHOICE>Schulung</CHOICE><CHOICE>Fachbesprechung</CHOICE><CHOICE>Messe</CHOICE></CHOICES></Field>",
    "Scope": "/sites/.../Lists/...",
    "Sealed": false,
    "ShowInFiltersPane": 0,
    "Sortable": true,
    "StaticName": "...",
    "Title": "Category",
    "FieldTypeKind": 6,
    "TypeAsString": "Choice",
    "TypeDisplayName": "Auswahl",
    "TypeShortDescription": "Auswahl (MenĂ¼)",
    "ValidationFormula": null,
    "ValidationMessage": null,
    "FillInChoice": false,
    "Mappings": null,
    "Choices": {
        "__metadata": {
            "type": "Collection(Edm.String)"
        },
        "results": [
            "SocialEvent",
            "Schulung",
            "Fachbesprechung",
            "Messe"
        ]
    },
    "EditFormat": 0
}

But when I change the mode to edit, the same code gives me the following result (I shortened it, because the result is 10.000+ lines):

{
    "user": {
        "@odata.context": "...",
        "@odata.type": "#SP.User",
        "@odata.id": "...",
        "@odata.editLink": "Web/GetUserById(17)",
        "Id": 17,
        "IsHiddenInUI": false,
        "LoginName": "...",
        "Title": "...",
        "PrincipalType": 1,
        "Email": "...",
        "Expiration": "",
        "IsEmailAuthenticationGuestUser": false,
        "IsShareByEmailGuestUser": false,
        "IsSiteAdmin": true,
        "UserId": {
            "NameId": "...",
            "NameIdIssuer": "urn:federation:microsoftonline"
        },
        "UserPrincipalName": "..."
    },
    "item": {
        "@odata.context": "...",
        "@odata.type": "#SP.Data.SitePagesItem",
        "@odata.id": "...",
        "@odata.etag": "\"363\"",
        "@odata.editLink": "...",
        "FileSystemObjectType": 0,
        "Id": 1,
        "ContentTypeId": "...",
        "OData__ModerationComments": null,
        "ComplianceAssetId": null,
        "Title": "Homepage",
        "PageLayoutType": "Home",
        "BannerImageUrl": {
            "Description": "...",
            "Url": "..."
        },
        "Description": "...",
        "PromotedState": 0,
        "FirstPublishedDate": null,
        "LayoutWebpartsContent": null,
        "OData__AuthorBylineId": null,
        "OData__TopicHeader": null,
        "OData__SPSitePageFlags": null,
        "OData__SPCallToAction": null,
        "OData__OriginalSourceUrl": null,
        "OData__OriginalSourceSiteId": null,
        "OData__OriginalSourceWebId": null,
        "OData__OriginalSourceListId": null,
        "OData__OriginalSourceItemId": null,
        "ID": 1,
        "Created": "2022-07-30T16:11:23-07:00",
        "AuthorId": 0,
        "Modified": "2022-09-28T00:45:46-07:00",
        "EditorId": 0,
        "OData__ModerationStatus": 3,
        "CheckoutUserId": 0,
        "UniqueId": "...",
        "owshiddenversion": 363,
        "OData__UIVersionString": "41.5",
        "GUID": "..."
    },
    "itemProperties": {}
    ...
}

The following versions are installed:

"@pnp/common": "1.3.9",
"@pnp/logging": "1.3.9",
"@pnp/odata": "1.3.9",
"@pnp/sp": "1.3.9",

Update: I installed the web part in different site collections within the tenant, which resulted in the same error. Now I have installed the web part in another tenant, where the problem don't occur. Unfortunately, I still cannot determine where the error is.

IngoH
  • 159
  • 7

0 Answers0