Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI-3942: add record id arg to addRecords #104

Merged
merged 2 commits into from
Oct 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
akbertram marked this conversation as resolved.
Show resolved Hide resolved

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
Loading