Skip to content

Commit

Permalink
Merge pull request #104 from jamiewhths/ai-3942
Browse files Browse the repository at this point in the history
AI-3942: add record id arg to addRecords
  • Loading branch information
akbertram authored Oct 28, 2023
2 parents b7cdf6a + fe5874e commit 2b4bcf6
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions R/records.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ recordExists <- function(formId, recordId) {
#' @param formId the id of the form to which the record should be added
#' @param parentRecordId the id of this record's parent record, if the form is a subform
#' @param fieldValues a named list of fields to change.
#' @param recordId the id of the new record when a custom id is desired. The given id must be in cuid-compatible format.
#' @export
#' @family record functions
#' @examples
Expand Down Expand Up @@ -73,12 +74,21 @@ recordExists <- function(formId, recordId) {
#' ))
#'
#' }
addRecord <- function(formId, parentRecordId = NA_character_, fieldValues) {
addRecord <- function(formId, parentRecordId = NA_character_, fieldValues, recordId = NA_character_) {
stopifnot(is.character(formId))
stopifnot(is.character(parentRecordId))
stopifnot(is.list(fieldValues))

recordId <- cuid()
stopifnot(is.character(recordId))

if (identical(recordId, NA_character_)) {
# generate a record id if not provided
recordId <- cuid()
} else {
# check provided record id does not exist before continuing
if (recordExists(formId, recordId)) {
stop(sprintf("Record %s in form %s already exists.", recordId, formId))
}
}
changes <- list(
list(
formId = formId,
Expand Down

0 comments on commit 2b4bcf6

Please sign in to comment.