diff --git a/docs/sp/fields.md b/docs/sp/fields.md index 48449e729..8ec6ce5f8 100644 --- a/docs/sp/fields.md +++ b/docs/sp/fields.md @@ -254,6 +254,31 @@ const r = await field.field.select("Id")(); console.log(r.Id); ``` +### Add an Image Field + +Use the addImageField method to create a new image field. + +```TypeScript +import { spfi } from "@pnp/sp"; +import { IFieldAddResult, FieldTypes } from "@pnp/sp/fields/types"; +import "@pnp/sp/webs"; +import "@pnp/sp/lists"; +import "@pnp/sp/fields"; + +const sp = spfi(...); + +// create a new image field called 'My Field' in web. +const field: IFieldAddResult = await sp.web.fields.addImageField("My Field"); +// create a new image field called 'My Field' in the list 'My List'. +const field2: IFieldAddResult = await sp.web.lists.getByTitle("My List").fields.addImageField("My Field"); + +// we can use this 'field' variable to run more queries on the field: +const r = await field.field.select("Id")(); + +// log the field Id to console +console.log(r.Id); +``` + ### Add a Multi-line Text Field Use the addMultilineText method to create a new multi-line text field. diff --git a/packages/sp/fields/types.ts b/packages/sp/fields/types.ts index 3b801afb6..bc013ec9d 100644 --- a/packages/sp/fields/types.ts +++ b/packages/sp/fields/types.ts @@ -485,7 +485,7 @@ const FieldTypeClassMapping = { [FieldTypes.DateTime]:"SP.FieldDateTime", [FieldTypes.GridChoice]:"SP.FieldRatingScale", [FieldTypes.Guid]: "SP.FieldGuid", - [FieldTypes.Image]:"FieldMultiLineText", + [FieldTypes.Image]:"SP.FieldMultiLineText", [FieldTypes.Integer]:"SP.FieldNumber", [FieldTypes.Location]:"SP.FieldLocation", [FieldTypes.Lookup]:"SP.FieldLookup", diff --git a/test/sp/fields.ts b/test/sp/fields.ts index 2684e3843..1ff44b14e 100644 --- a/test/sp/fields.ts +++ b/test/sp/fields.ts @@ -64,6 +64,11 @@ describe("Fields", function () { const field = await this.pnp.sp.web.fields.addText(testFieldNameRand, { Group: testFieldGroup }); return expect(field.data.Title).to.be.equal(testFieldNameRand); }); + it("addImageField", async function () { + const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`; + const field = await this.pnp.sp.web.fields.addImageField(testFieldNameRand, { Group: testFieldGroup}); + return expect(field.data.Title).to.be.equal(testFieldNameRand); + }); it("addNumber", async function () { const testFieldNameRand = `${testFieldName}_${getRandomString(10)}`; const field = await this.pnp.sp.web.fields.addNumber(testFieldNameRand, { Group: testFieldGroup });