From a847721773924d3e0e2be8213533c889d9bb816b Mon Sep 17 00:00:00 2001 From: Julie Turner Date: Tue, 24 Sep 2024 14:25:19 +0000 Subject: [PATCH] Documentation updates #3138 --- docs/sp/folders.md | 5 +++-- docs/sp/items.md | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/docs/sp/folders.md b/docs/sp/folders.md index a56987d49..f1f3c116d 100644 --- a/docs/sp/folders.md +++ b/docs/sp/folders.md @@ -532,7 +532,7 @@ const folder: IFolder = await sp.web.rootFolder.folders.getByUrl("SiteAssets").a ### getFolderById -You can get a folder by Id from a web. +You can get a folder by UniqueId from a web. ```TypeScript import { spfi } from "@pnp/sp"; @@ -542,7 +542,8 @@ import { IFolder } from "@pnp/sp/folders"; const sp = spfi(...); -const folder: IFolder = sp.web.getFolderById("2b281c7b-ece9-4b76-82f9-f5cf5e152ba0"); +const folderItem = sp.web.lists.getByTitle("My List").items.getById(1).select("UniqueId")() +const folder: IFolder = sp.web.getFolderById(folderItem.UniqueId); ``` ### getParentInfos diff --git a/docs/sp/items.md b/docs/sp/items.md index bb2b08cfc..b0784e5da 100644 --- a/docs/sp/items.md +++ b/docs/sp/items.md @@ -367,11 +367,13 @@ await execute(); console.log("Done"); ``` + ### Update Taxonomy field Note: Updating Taxonomy field for a File item should be handled differently. Instead of using update(), use validateUpdateListItem(). Please see below -List Item +#### List Item + ```TypeScript import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; @@ -385,7 +387,9 @@ await sp.web.lists.getByTitle("Demo").items.getById(1).update({ }); ``` -File List Item + +#### File List Item + ```TypeScript import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; @@ -407,6 +411,8 @@ _Based on [this excellent article](https://www.aerieconsulting.com/blog/update-u As he says you must update a hidden field to get this to work via REST. My meta data field accepting multiple values is called "MultiMetaData". +#### List Item + ```TypeScript import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; @@ -433,7 +439,9 @@ await sp.web.lists.getByTitle("TestList").items.getById(newItem.Id).update(updat ``` #### File List Item + To update a multi-value taxonomy field on a file item, a different serialization is needed. + ```TypeScript import { spfi } from "@pnp/sp"; import "@pnp/sp/webs"; @@ -482,6 +490,30 @@ const update = await sp.web.lists.getByTitle("Price").items.getById(7).select('* ]); ``` +### Update Location Field + +This code shows how to update a location field's coordinates. + +```TypeScript +import { spfi } from "@pnp/sp"; +import "@pnp/sp/webs"; +import "@pnp/sp/lists"; +import "@pnp/sp/items"; + +const sp = spfi(...); +const coordinates = { + Latitude: 47.672082, + Longitude: -122.1409983 +} + +const projectId = 1; +const project = sp.web.lists.getByTitle("My List").items.getById(projectId).select("Id, ProjectLocation")() +const projectLocation = JSON.parse(project.ProjectLocation); +projectLocation.Coordinates = coordinates; +const ProjectLocation = JSON.stringify(projectLocation); +const update = await sp.web.lists.getByTitle("My List").items.getById(projectId).update({ ProjectLocation }); +``` + ## Recycle To send an item to the recycle bin use recycle.