Create SharePoint list lookup column and update lookup column items
Source:R/sp_list.R, R/sp_user_info.R
create_sp_list_lookup_column.Rdupdate_sp_list_person_items() is a variant of
update_sp_list_lookup_items() for person or group columns. Person or group
columns are a type of lookup column where the lookup list is the hidden
"User Information List" for the site. By default, users are matched by email
address (ignoring case). Users that have never accessed the site are not
included in the "User Information List" and can't be matched.
Usage
create_sp_list_lookup_column(
sp_list = NULL,
column_name,
lookup_list,
lookup_list_column = column_name,
...,
list_name = NULL,
site = NULL,
site_url = NULL,
call = caller_env()
)
create_sp_list_person_column(
sp_list = NULL,
column_name,
...,
allow_multiple_selection = NULL,
display_as = NULL,
from_type = "peopleOnly",
list_name = NULL,
site = NULL,
site_url = NULL,
allow_multiple = deprecated(),
call = caller_env()
)
update_sp_list_lookup_items(
data = NULL,
sp_list = NULL,
column_name,
lookup_list_data = NULL,
lookup_list = NULL,
join_column = column_name,
lookup_join_column = join_column,
...,
.id = "id",
ignore_case = FALSE,
na_fields = c("drop", "replace"),
.progress = TRUE,
call = caller_env()
)
fmt_sp_list_lookup_items(
data,
column_name,
lookup_list_data = NULL,
lookup_list = NULL,
lookup_join_column = column_name,
...,
.id = "id",
ignore_case = FALSE,
call = caller_env()
)
update_sp_list_person_items(
data = NULL,
sp_list = NULL,
column_name,
join_column = column_name,
user_column = "EMail",
user_info_data = NULL,
allow_hidden = FALSE,
...,
.id = "id",
na_fields = c("drop", "replace"),
.progress = TRUE,
call = caller_env()
)Arguments
- sp_list
A
ms_listobject. If supplied,list_name,site, andsite_urlare all ignored.- column_name
Name of the lookup (or person or group) column. For
create_sp_list_lookup_column(), the name of the new column. Forupdate_sp_list_lookup_items()andupdate_sp_list_person_items(), lookup ID values are written to the"{column_name}LookupId"field. Forfmt_sp_list_lookup_items(), one or more column (or record element) names indatato format.- lookup_list
The lookup list as a
ms_listobject, list name, or list URL. The lookup list must be in the same site assp_listand a list name is retrieved from the same site assp_list. Forupdate_sp_list_lookup_items()andfmt_sp_list_lookup_items(),lookup_listis only used to retrievelookup_list_dataif not supplied. Forfmt_sp_list_lookup_items(), a list name requires site information (e.g.site_url) passed with....- lookup_list_column
Name of lookup column in the lookup list to use. Graph property:
columnName.- ...
Arguments passed on to
create_lookup_column.col_typeColumn type. Defaults to "text". Must be one of "boolean", "calculated", "choice", "currency", "dateTime", "lookup", "number", "personOrGroup", "text", "term", "hyperlinkOrPicture", "thumbnail", "contentApprovalStatus", or "geolocation".
enforce_uniqueEnforce unique values in column. Graph property:
enforceUniqueValues.hiddenIf
TRUE, column will be hidden by default. Graph property:hidden.deletableIf
TRUE, column can't be deleted separate from the list. Graph property:isDeletable.requiredIf
TRUE, column will be required. Graph property:required.defaultDefault value set by helper
get_column_default()function. Graph property:defaultValue.descriptionColumn description. Graph property:
description.display_nameColumn display name. Graph property:
displayName.displaynamevalidationColumn validation created with
column_validation(). Graph property:validation.indexed,sealed,propagate_changes,read_only,idAdditional arguments used by
create_column_definition(). Graph properties:indexed,isSealed,propagateChanges,readOnly, andid.multiple_linesLogical. If
TRUE, allow multiple lines of text. Graph property:allowMultipleLines.append_changesLogical. If
TRUE, append changes to existing value for column. Graph property:appendChangesToExistingText.linesWhole number. Size of the text box. Graph property:
linesForEditing.max_lengthWhole number. Max length in number of characters. Graph property:
maxLength.text_typeOne of
c("plain", "richText"). Graph property:textType.choicesA character vector of choice options. Graph property:
choices.allow_naIf
TRUE, allow NA values inchoices.na_replacementUsed as
replacementbystringr::str_replace_na()onchoicesif they contain NA values.allow_textIf
TRUE, allow text entry in the choice column. Graph property:allowTextEntry.decimal_placesOne of
c("automatic", "none", "one", "two", "three", "four", "five")or a whole number between 0 and 5. Graph property:decimalPlaces.max,minMinimum and maximum values allowed in number column. Graph properties:
maximumandminimum.decimalsformatFor
create_datetime_column(),"dateOnly"or"dateTime". Graph property:format.localeLocale used to set the currency symbol, e.g.
"en-us". Graph property:locale.formulaRequired string with formula for calculated column definition. See examples of common formulas in lists. Reference existing columns using the display name enclosed in square brackets. The formula must start with an equals sign
"="which this function appends to the formula text if it is missing. The formula is processed withglue::glue(). Graph property:formula.output_typeValue type returned by calculated formula. One of
c("text", "boolean", "currency", "dateTime", "number"). Defaults to"text". Graph property:outputType.allow_multiple_valuesIf
TRUE, allow a lookup or term column to store multiple values. Graph property:allowMultipleValues.allow_unlimited_lengthIf
TRUE, allow lookup column to return any length value. Graph property:allowUnlimitedLength.primary_lookup_column_idIf column definition is for a secondary column, the primary lookup column ID must be supplied. Graph property:
primaryLookupColumnId.is_pictureLogical indicator for display of hyperlink value as link (
FALSE, default forcreate_hyperlink_column()) or image (TRUE, default forcreate_picture_column()). Graph property:isPicture.show_full_nameIf
TRUE, display the entire term path. Graph property:showFullyQualifiedName.splitcharacter vector (or object which can be coerced to such) containing regular expression(s) (unless
fixed = TRUE) to use for splitting. If empty matches occur, in particular ifsplithas length 0,xis split into single characters. Ifsplithas length greater than 1, it is re-cycled alongx.
- list_name
List name. Required if
sp_listisNULL.- site
A
ms_siteobject. Ifsiteis supplied,site_url,site_name, andsite_idare ignored.- site_url
A SharePoint site URL in the format "https://[tenant name].sharepoint.com/sites/[site name]". Any SharePoint item or document URL can also be parsed to build a site URL using the tenant and site name included in the URL.
- call
The execution environment of a currently running function, e.g.
caller_env(). The function will be mentioned in error messages as the source of the error. See thecallargument ofabort()for more information.- allow_multiple_selection
If
TRUE, allow a person or group column to store multiple values. Graph property:allowMultipleSelection.- display_as
Value displayed as option. For
create_choice_columnone ofc("checkBoxes", "dropDownMenu", "radioButtons"). Forcreate_number_column, one ofc("number", "percentage"). Forcreate_datetime_column, one ofc("default", "friendly", "standard"). Graph property:displayAs.- from_type
What type of resources to choose from. Defaults to "peopleOnly" for
create_person_column()or "peopleAndGroups" forcreate_group_column(). Graph property:chooseFromType.- allow_multiple
Use
allow_multiple_valuesforcreate_lookup_column()andcreate_term_column()orallow_multiple_selectionforcreate_person_column()andcreate_group_column().- data
Optional. A data frame, a list of named lists (one record per item), or a single named list record with item ID values (
.id) and join values (join_column) for the items to update. A single record or a named list of records is returned byfmt_sp_list_lookup_items()as an unnamed list of records. IfNULL, items are retrieved fromsp_list. Required forfmt_sp_list_lookup_items()wheredatamust include allcolumn_namevalues as column (or record element) names.- lookup_list_data
Optional. A data frame or a list of named lists with item ID values (
.id) and unique join values (lookup_join_column) for the lookup list items. IfNULL, items are retrieved fromlookup_list.- join_column
Name of column (or record element) in
datato match items to lookup list items. Defaults tocolumn_name. Items without a matching lookup list item are not updated whenna_fields = "drop".- lookup_join_column
Name of column (or record element) in
lookup_list_datawith values to match tojoin_columnvalues. Defaults tojoin_column. Forfmt_sp_list_lookup_items(),lookup_join_columnmust be length 1 or the same length ascolumn_nameand defaults tocolumn_name.- .id
Name of column (or record element) with item ID values in
dataandlookup_list_data. Defaults to "id".- ignore_case
If
TRUE, ignore case when matching join values. Defaults toFALSE.- na_fields
How to handle
NAfields in input data. One of"drop"(removeNAand empty fields, e.g. a multi-select value ofcharacter(0), before updating list items, leaving existing values in place) or"replace"(overwrite existing list values with new replacement NA values or, for multi-value fields, an empty selection).- .progress
Whether to show a progress bar. Use
TRUEto turn on a basic progress bar, use a string to give it a name, or see progress_bars for more details.- user_column
Name of column (or record element) in
user_info_datawith values to match tojoin_columnvalues. Defaults to"EMail".- user_info_data
Optional. A data frame or an unnamed list of named lists from the "User Information List" for the site. If
NULL, items are retrieved withlist_sp_site_user_info()for the site ofsp_list.If
TRUE, include users withUserInfoHidden = TRUEin the possible matches. Defaults toFALSE.
Details
create_sp_list_lookup_column() is a wrapper for create_lookup_column()
and create_sp_list_column() that creates a lookup column in a list
(sp_list) using a column from a second list in the same site (the "lookup"
list). create_sp_list_person_column() is a wrapper for
create_person_column() and create_sp_list_column() that creates a person
or group column.
fmt_sp_list_lookup_items() formats one or more lookup (or person or group)
columns in data by replacing the values with matching lookup list item ID
values and renaming the columns to "{column_name}LookupId". Use the output
with create_sp_list_items() or update_sp_list_items().
Values in data that can't be matched to a lookup list item are listed in a
message and replaced with NA values. Missing values are never matched.