The Property Policy Number Does Not Exist Rest API

Recently, when attempting to create a folder with metadata using SharePoint REST API, I encountered an error: ‘The property ‘PolicyNumber’ does not exist on type ‘SP.Data.FinanceItem’. Make sure to only use property names that are defined by the type.’

You can refer to the image below.

The property '__metadata' does not exist on type 'SP.Data

In this SharePoint tutorial, we will explore how I got the error: ‘The property ‘PolicyNumber’ does not exist on type ‘SP.Data.FinanceItem’. Make sure to only use property names that are defined by the type.’ and how to fix it.

Error: The Property Policy Number Does Not Exist Rest API

When I was creating a folder with metadata using SharePoint Rest api, I used the code below to execute:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
    function CreateFolder() {
        jQuery.ajax({
            "url": _spPageContextInfo.siteAbsoluteUrl + "/_api/Web/Folders/add('/sites/Sales/Finance/Policies/Policy')",
            "type": "POST",
            "headers": {
                "accept": "application/json; odata=verbose",
                "content-type": "application/json; odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },
            success: function(data) {
                console.log(data);
                GetFolder(data);
            },
            error: function(xhr, status, error) {
                console.log(xhr.responseText);
                alert("Error occurred: " + xhr.responseText);
            }
        });
    }

    function GetFolder(data) {
        var url = _spPageContextInfo.siteAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('/sites/Sales/Finance/Policies/Policy')?$expand=ListItemAllFields";

        $.getJSON(url).then(function(data) {
            console.log(data.ListItemAllFields.ID);
            UpdateFolder(data.ListItemAllFields.ID);
        });
    }

    function UpdateFolder(id) {
        $.ajax({
            url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('Finance')/items(" + id + ")",
            type: "POST",
            data: JSON.stringify({
                "__metadata": {
                    type: "SP.Data.FinanceItem"
                },
                "Policy_x0020_Number": "INV001"
            }),
            headers: {
                "Accept": "application/json;odata=verbose",
                "Content-Type": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                "IF-MATCH": "*",
                "X-HTTP-Method": "MERGE"
            },
            success: function(data, status, xhr) {
                console.log("Success");
            },
            error: function(xhr, status, error) {
                console.log(xhr.responseText);
                alert("Error occurred: " + xhr.responseText);
            }
        });
    }

    CreateFolder();
</script>

When I ran this code in SharePoint, I got the error: “The property ‘PolicyNumber’ does not exist on type ‘SP.Data.FinanceItem’. Make sure to only use property names that are defined by the type.’

The property '__metadata' does not exist on type 'SP.Data

If you focus on this part of the code in the UpdateFolder() function, you can see that we are providing metadata for the ‘Policy Number’ property.

data: JSON.stringify({
                "__metadata": {
                    type: "SP.Data.FinanceItem"
                },
                "Policy_x0020_Number": "INV001"
            }),

This error message typically indicates that we are trying to access a property named ‘PolicyNumber’ on an object of type ‘SP.Data.FinanceItem’, but such a property is not defined for that type.

The property 'InvoiceNumber' does not exist on type 'SP.Data.FinanceItem

When SharePoint rest api tries to access a property [Policy Number] that doesn’t exist for that type, you’ll get the error.

See also  How to Import Data from Excel to a SharePoint list using Power Automate?

To solve this, we will add the property name to SharePoint Folder and make sure it matches the actual property names defined for the ‘FinanceItem’ type in your SharePoint Rest api code.

Solved: The Property Policy Number Does Not Exist Rest API

To fix this error, we need to create a “Policy Number” column in the SharePoint folder.

To create the property in the SharePoint Folder on the classic site, follow these steps: click on the Library -> click on “Create Column” -> provide the Column Name, and select the Single line of text data type -> click on OK.

The property 'InvoiceNumber' does not exist on type 'SP.Data.FinanceItem error

Now, you can see the Policy Number column in the Policies folder in SharePoint.

The property 'PolicyNumber' does not exist on type 'SP.Data.FinanceItem' error in SharePoint

Now, if I run the code, you can see there will be no error, and the folder [Policy] will be created successfully with metadata using SharePoint rest api.

The property 'PolicyNumber' does not exist on type 'SP.Data.FinanceItem' error in SharePoint rest api

Also, you may like:

Conclusion

In this SharePoint tutorial, we saw how to fix the error: ‘The property ‘PolicyNumber’ does not exist on type ‘SP.Data.FinanceItem’. Make sure only to use property names that are defined by the type‘ while working with the rest of api.

>