frail-apricot
frail-apricot7mo ago

How to Update two or more fields in strap using logical operations in refine

Hi everyone, I´m new here, I want to update Hi everyone, I´m new here developing web apps and in javascript/typescript. I´m using strapiv4/refine/antd/vite So, I have "produto" collection with fields "prodname", "prodstock", "provisionQnt" and so on.. How can I update the "prodstock" field making this logical operations: "prodstock = prodstock + provisionQnt". I hope I was clear.
No description
No description
2 Replies
kapa.ai
kapa.ai7mo ago
Hi @sly0074. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in the extracts, you can use the useUpdate hook from refine to update a record in your "produto" collection. However, the extracts do not provide a direct example of updating a field based on its current value and another field's value. Here's a basic example of how you might use the useUpdate hook:
import { useUpdate } from "@refinedev/core";

const { mutate } = useUpdate();

const handleUpdate = async () => {
await mutate({
resource: "produto",
values: {
// your updated values
},
id: 1, // the id of the record you want to update
});
};
import { useUpdate } from "@refinedev/core";

const { mutate } = useUpdate();

const handleUpdate = async () => {
await mutate({
resource: "produto",
values: {
// your updated values
},
id: 1, // the id of the record you want to update
});
};
In your case, you want to update the "prodstock" field based on its current value and the value of "provisionQnt". You might need to first fetch the current values of these fields, perform the calculation, and then use the useUpdate hook to update the "prodstock" field. Unfortunately, the provided extracts do not contain enough information to provide a more specific answer. I would recommend checking the refine documentation (https://refine.dev/docs) for more information on how to use the useUpdate hook and other refine features. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7mo ago
<@1172098337760096258> kapa.ai is still learning and improving, please let us know how it did by reacting below