I'm working with @azure/data-tables and my aim is to update a table. I use updateEntity as advised in the documentation (https://docs.microsoft.com/en-us/javascript/api/@azure/data-tables/tableclient?view=azure-node-latest#@azure-data-tables-tableclient-updateentity). Unfortunately I constantly get an exception: "Azure updateEntity - Cannot read properties of undefined (reading 'replace')". I've definitely provided a proper account and accountKey. What's interesting, createEntity works just fine - I can see an entry added to my table.
The code in index.js:
const { TableClient, AzureNamedKeyCredential } = require("@azure/data-tables");
module.exports = async function (context, req) {
const account = ""
const accountKey = ""
const tableName = "Person"
const sharedKeyCredential = new AzureNamedKeyCredential(account, accountKey);
const client = new TableClient(
`https://${account}.table.core.windows.net`,
`${tableName}`,
sharedKeyCredential
);
const entity = {
PartitionKey: "1",
RowKey: "1",
Name: 'Mathilde'
};
await client.updateEntity(entity);
}
I've tried:
- adding with an existing PartitionKey/RowKey and a unique PartitionKey/RowKey
- trying to update to a different table
- turning RowKey to a number
- debugging and checking whether anything is undefined (no, apparently everything is fine - both for entity and client)
- checking whether other methods would work (yes, createEntity works)
The table I'm working on currently consists of three properties (PartitionKey, RowKey, and Name), and all are set to be Strings.
In case you want to see it, here is my function.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "input",
"methods": ["put"],
"route": "updatingUsers"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false
}
If you could help me with this issue I would be so thankful!
CodePudding user response:
I've found out what was wrong. Apparently, if your property has a name starting with an uppercase, then you have to use uppercase as well, BUT even though both PartitionKey and RowKey are uppercased in a table, they have to be lowercased in code. Quite weird but it solves all the errors. The case is closed :)