Access currentRow in Mapped value field

Hi there

In a table I am working on, I list a couple of access tokes that can already exist or not. There are three relevant fields for my question:

  • Valid Until: If the user already has an access token, the current end-date is shown here
  • Start date: the start date is always today, as a new card would be made today
  • End date: this is where it gets tricky. If there is no Valid Until value, I want the end date to be one year from the start date, otherwise I want it to be one year from the valid until date.

To do this, I would like to access the until date in the row but I cannot seem to access currentRow in the mapped values for end date. (Valid until is looked up via a short script and an api call, so I would like to refer from using that api call multiple times)

Right now my mapped value for end date looks like this:

accesstokenapicall?.due_date === undefined 
  ? moment.locale.add(1, "years")
  : moment(accesstokenapicall.due_date).add(1, "years")

It would be nicer if I could just use currentRow.validUntil.due_date instead of the entire call and find function again.

Hello @Allys1098,

In your situation the best course of action to prevent duplicate code would be to add those external values to the datasource of the table, that way you would have validUntil as a property of currentSourceRow, which you could then use in end date mapped value.
You can add apicall data in the datasource of the table with JS or in the original data source by using the transform results tab (if it's a sql or api call).

Let me know if this helps!

1 Like

Hello @Allys1098
Can you please provide json or screenshot

Without more info, I agree with @GuilhermeSilva's suggestion. It would be helpful to collect as much of the data as possible at once and pass it into the data source

1 Like

Hi @GuilhermeSilva

Thank you for your response but sadly I work with an external API and i cannot just add information to their data, otherwise that would be my solution as well. Right now I still do it with the different API calls.

The solution should work like this (and that is how it works at the moment)

In then end column is the code I provided in my question in the mapped value:

I sadly cannot share a json of the app itself because it holds sensitive information. My main question is just why I cannot access currentRow in that mapped value, only currentSourceRow seems to come up.

Hi @Allys1098

You can't access currentRow because in that mapped value, you're defining the currentRow property, so you would be creating a loop.

A possible solution is to go to your API call, use the 'transform results' section and add a new property, for example:

return ({...data, end_date: data.due_date == undefined ? moment().add(1, 'years') : moment(data.due_date).add(1, 'years') })

By doing this the property end_date would become part of the data that feeds the table, being easily accessible via currentSourceRow.

1 Like

I did not think of using transforms indeed! Thank you for adding that last idea.

1 Like