Hi all,
I’m trying to use the CSV actions to help my users import data in bulk. What I’m trying to do is use the CSV export action so that users can download the current data set, review it, add/update it in the CSV file. Then, they can save that file and use the CSV import action to upload all add/updates at once.
Currently, I am having an issue with the key values of the ref columns of the table that I’m using. Unlike this post: Export csv when I use the CSV export action on my table, the CSV file includes the labels of the ref columns, not the keys. This is handy for users to read but if users use the CSV import action with a CSV file that only has the label values, AppSheet won’t recognize the relationship of the those ref columns. I think this is caused by a Valid If expression that I’m using to make the columns alphabetical when chosen from a drop down (such as this: ORDERBY(ContactType[Id],[Name],FALSE). But to be honest I don’t know if that is the case because this expression doesn’t fix it:
IF(
CONTEXT(“ViewType”) = “Form”,
ORDERBY(Company[ID],[Name],FALSE),
ORDERBY(Company[ID], [ID])
)
To address this, I am creating a slice that will be used for CSV export/import actions and will include non-user friendly info such as the record ID’s, the actual column names, and the key values of the ref columns. I was able to display the record ID’s by a combination of using a Show If expression (such as: CONTEXT(“ViewType”)<> “Form”) and removing the column from the Column Order of the related view.
I am also able to display the actual column names by changing the Display Name expression from “First Name” to:
IF(
OR(
CONTEXT(“ViewType”) = “Table”, CONTEXT(“ViewType”) = “Form”, CONTEXT(“ViewType”) = “Detail”),
“First Name”,
“FirstName”
)
All of this info is to ask, what view type is the CSV export? The above expression is able to change the display name to “First Name” in all of the views in my app and change the display name to “FirstName” in the exported CSV file. But I think the expression would be a lot cleaner if I knew which of the these view types the CSV Export action used: View Types | AppSheet Help Center
Also, if you see any other errors in my thought process, please let me know. If my apps were tied to a spreadsheet data source I would probably have users just change it directly but I am using a SQL data source.
Hi @Darmund how are you able to get this done?
"when I use the CSV export action on my table, the CSV file includes the labels of the ref columns, not the keys"
I know this is an old thread, but for anyone else looking for answers on this, I found an alternative solution that worked for me. The only caveat is you cannot edit the Ref column through the export / import method.
Solution:
Remove the Ref column from the export view using a slice and excluding it. In Ref column's Initial Value field, add the following expression and replacing the Table, Table Key, and Ref Column with your apps data columns.
IFS(
CONTAINS(Table[Table Key],[Table Key]),
INDEX(SELECT(Table[Ref Column],[Table Key]=[_THISROW].[Table Key]),1)
)
This expression checks to see if the Key value already exists upon import and retains the same value that is already populated for the Ref column. If a new Key value is detected it will default the Ref value to be blank. This expression only works if your Ref column is not required.
Note: If your Ref column is marked as 'Required', the default value needs to be a valid Ref value instead of defaulting to blank. You would use this expression instead.
IF(
CONTAINS(Table[Table Key],[Table Key]),
INDEX(SELECT(Table[Ref Column],[Table Key]=[_THISROW].[Table Key]),1),
"insert default value or [Column] here"
)
Hope this helps another soul in a similar situation, took me many hours to this figure out.
User | Count |
---|---|
18 | |
11 | |
11 | |
8 | |
4 |