Hello @Dmytro
I have a sample code that you can use to accomplish what you want. Please note the statements below first:
1 - This is a custom code I provide you, if you really want to commit to this solution, you will be the owner and you might need to adapt it over time
2 - Our current implementation of the link widget forces a new tab to be opened. So when your users would like to access related data directly, a new browser tab will be opened redirecting them to the related data.
Here are the steps to get this working:
1 - First, create the smart field that will contain the link. I’ve taken your transactions collection, and I’ve added the smart field as below:
// forest/transactions.js
..
fields: [{
field: 'relatedData',
type: 'String',
},{
field: 'relatedDatapoints',
type: ['String'],
reference: 'transactions._id'
},
],
..
2 - Then, you need to compute and populate the smart field. We need to know the team of the current user to compute the URL, this is why we can’t use a simple smart field getter (which is not aware of the current user), we need to override the getAll transactions’ route (here we can get the current user’s team):
// routes/transactions
// Get a list of transactions
router.get('/transactions', permissionMiddlewareCreator.list(), (request, response, next) => {
const params = request.query;
const recordsGetter = new RecordsGetter(transactionsModel);
recordsGetter.getAll(params)
.then(records => {
records.forEach((record) => {
record.relatedData = `/[PROJECT_NAME]/[ENVIRONMENT_NAME]/${request.user.team}/data/transactions/index/record/transactions/${record._id}/has-many/transactions-relatedDatapoints`
});
return records;
})
.then(records => recordsGetter.serialize(records))
.then(recordsSerialized => response.send(recordsSerialized))
.catch(next);
});
3 - Update the relatedData
smart field settings to make it use the widget display link
4 - get back to your table view, and you should see the smart field with a link in it, which should redirect to the related of the record
In this snippet, PROJECT_NAME
is the name of the project this code will run for, ENVIRONMENT_NAME
is the name of the environment (eg server) this code will run on. You can store this two variables as environment variables for example, and adapt them accross you environments.
I adapted this code to make it fit your collections’ name, so it should run directly after you pasted it
Tell me if it helps
Steve.