-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Preserve the data inside fields that have changed types (within type changes that make sense, of course).
## changing field type from form-schema
## ... does not preserve data in changed fields??
## grab form schema from existing table: Recover_Record_EX1 in FIFES
fifstab <- queryTable(form = "cb62ijfl8k2ymxx3")
dplyr::glimpse(fifstab)
## NUMPAR is a 'quantity field'
formsch <- activityinfo::getFormSchema(formId = "cb62ijfl8k2ymxx3")
## change NUMPAR field type from 'quantity' to 'FREE_TEXT'
formsch$elements[[1]] <- purrr::list_modify(formsch$elements[[1]], type = "FREE_TEXT")
## Revert formschema classes to regular "list" so that JSON // ActivityInfo can parse it properly
## formSchema S3 class >>> list
class(formsch) <- "list"
## formField S3 class >>> list class(formsch$elements[[1]])
formsch$elements <- lapply(formsch$elements, function(e) {
class(e) <- "list"
e
})
## Update schema with changes back to database
updateFormSchema(schema = formsch)
Currently doesn't work, data is wiped away when underlying field type changes. This was actually a Feature request brought up by project staff originally but since I knew about the updateFormSchema() function I had told them they could just use the R package. But unfortunately with the above problem, it's a harder sell as project staff don't want to lose data that already exists in the fields.
Of course, values getting wiped makes sense if I'm changing like DATE to numeric or Attachment to text or some other weird conversion but for something like text to quantity (and vice-versa), which is a conversion that's going to happen a lot (whether due to a mistake or otherwise), it would be nice if we could preserve the underlying values somehow?