From 0cad17af44d29f4c957eb9645d180ec32b8dc205 Mon Sep 17 00:00:00 2001 From: Jamie Whitehouse Date: Tue, 24 Oct 2023 14:21:45 +0200 Subject: [PATCH] AI-3942: add record id arg to addRecords --- R/records.R | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/R/records.R b/R/records.R index 09aa5f1..dffb3b4 100644 --- a/R/records.R +++ b/R/records.R @@ -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 @@ -73,12 +74,16 @@ 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() + } changes <- list( list( formId = formId,