SharePoint Online: cree un elemento de lista basado en un tipo de contenido específico
Requisito: Agregar un elemento de lista con un tipo de contenido específico en SharePoint Online.
¿Cómo agregar un nuevo elemento de lista de un tipo de contenido específico en SharePoint Online?
Digamos que tenemos un tipo de contenido personalizado, "Contactos comerciales" para la lista de contactos y queremos agregar un nuevo elemento del tipo de contenido determinado. Para crear un nuevo elemento de lista de un tipo de contenido específico en SharePoint Online, simplemente seleccione el tipo de contenido deseado en el menú "Nuevo" de esa lista.
En mi caso, seleccioné "Contactos comerciales" en el menú desplegable "Nuevo" en lugar de simplemente hacer clic en el botón "Nuevo" de la lista.
PowerShell para crear un elemento de lista de un tipo de contenido particular:
¿Está buscando una secuencia de comandos de PowerShell para crear un elemento de lista de un tipo de contenido particular en SharePoint Online? Esta publicación de blog le mostrará cómo usar PowerShell para crear un elemento de lista del tipo de contenido "Contactos comerciales" en una lista de SharePoint Online.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ListName="Contacts"
$ContentTypeName="Business Contacts"
Try {
#Get Credentials to connect
$Cred= Get-Credential
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()
#Get the content type from list
$ContentTypeColl = $List.ContentTypes
$Ctx.Load($ContentTypeColl)
$Ctx.ExecuteQuery()
#Get the content type
$CType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
If($CType -ne $Null)
{
#Create a List Item of specific content type
$ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ListItem = $List.AddItem($ListItemInfo)
#Set List Item Fields - Internal Names
$ListItem["Title"] = "Ruta"
$ListItem["FirstName"] = "Graciela"
$ListItem["Company"] = "Buckley Miller & Wright"
$ListItem["WorkPhone"] = "440-780-8425"
$ListItem["Email"] = "gruta@cox.net"
#Set Content type for the Item
$ListItem["ContentTypeId"] = $CType.ID
$ListItem.Update()
$Ctx.ExecuteQuery()
Write-host "New Item Added to the List!" -ForegroundColor Green
}
else
{
Write-host "Content Type Doesn't exist in the List!" -ForegroundColor Yellow
}
}
Catch {
write-host -f Red "Error Adding Items to List!" $_.Exception.Message
}
PnP PowerShell para agregar un elemento de lista de un tipo de contenido específico
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Retail"
$ContentTypeName = "Business Contacts"
$ListName = "Contacts"
#Connect to SharePoint Online Site
Connect-PnPOnline -Url $SiteURL -Interactive
#Create List Item based on specific content type
Add-PnPListItem -List $ListName -ContentType $ContentTypeName -Values @{"Title" = "Ruta" ; "FirstName" ="Graciela"}
