Feature(s) impacted
Hello,
I want to duplicate a record under certain conditions in my route router.put('/:collection/:recordId')
.
When those conditions are met, after the duplication, I want to redirect to the newly created record.
Observed behavior
I can’t find a way to do the redirection.
The only thing that seems to work is
return response.status(statusThatIsNot200).send('Some random message')
But the express redirection is not working.
Types let me think that it is possible but I’m getting this error An error occurred when trying to edit ${collection}: unexpected error
.
You can reproduce it with
router.put(`/${collection}/:recordId`, permissionMiddlewareCreator.update(), async (req, res, next) => {
return res.redirect(`https://app.forestadmin.com/${projectName}/${envName}/${teamName}/data/${collection}/index/record/${collection}/${anotherId}/details`)
})
Expected behavior
I expect to be able to use some functions of the express response or to have an alternative to redirect to a given url.
Failure Logs
There is no failure logs.
Only the badge in the app with the error An error occurred when trying to edit ${collection}: unexpected error
.
Context
- Project name: mytraiteur
- Team name: Operations
- Environment name: Development | marco2
- Agent technology: Legacy version: Express
- Agent (forest package) name & version: forest-express-sequelize@9.3.9
- Database type: MYSQL
- Recent changes made on your end if any: none
Hello,
To find an alternative, why do you want to redirect the user after an update?
Forestadmin does not support the redirection on the detail view because the frontend application needs to receive the update result
If you really want to do a redirection, you can probably use a smart action to update record and do a redirection after the execution. But the edition is not from the detail view.
Because I want to duplicate the record under certain conditions in my route put
instead of updating the current record.
So I want the user to see the new record because the old one hasn’t been updated at all.
For my usecase, it’s when I update a product’s price, I want to disable the old one and create a new one with the new price.
The only problem I’m facing is the redirection.
I thought of using a smart action but it’s not as simple as updating a record for our users.
I can return the old one to avoid the error.
But if I do that, is there a way to change the success message ?
And maybe put a link in it ?
Ok I understand your needs. You want to have an history of your price.
Unfortunately is not possible. Smart Action is developed in part to support this case. You can create a smart action: Edit Price
with a dedicated form and set the price as readonly in the layout. With this trick, customers can’t edit the price but they can always edit others records. If they want to edit the price, they can use the action
Ok thanks.
Just a last question, is there a way to do this in the latest version of the Node.js forestadmin agent ?
is there a way to do this in the latest version of the Node.js forestadmin agent ?
Unfortunately, no, the limitation comes from the designed Forestadmin workflow, not the agent but I still recommend using this version