powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Add-PnPPageWebPart Cannot Set Images for ImageGallery

Open leahann opened this issue 1 year ago • 1 comments

Reporting an Issue or Missing Feature

Very similar to some earlier bugs related to the Image web part, I'm unable to add images to the Image Gallery web part. I can add an Image Gallery web part that pulls dynamically from a library, but our use case requires select images in a carousel.

Expected behavior

Images appear in the web part

Actual behavior

Spots for the images appear in the web part, but the images aren't visible. image

Steps to reproduce behavior

I've tried both Add-PnPPageWebPart and Set-PnPPageWebPart, with the same results.

Add-PnPPageWebPart -Page $pageTitle -DefaultWebPartType ImageGallery -Section 1 -Column 1 -WebPartProperties $wpPropJson

Where images json in the $wpPropJson variable is like below. The galleryImgId looks like it might be generated when the images are added manually from the front end. I've tried a few different variations on this.

"images": [
          {  
            "siteId": "18e1477c-5056-4853-8951-15268c006a7f",  
            "webId": "d1628f6a-d25e-4641-94cd-2de258f3b1dc",  
            "listId": "{C2DF79CF-273B-4225-9DC4-86A907D46E2F}",  
            "id": "35707cf1-ef0d-49ae-abdd-72f2567a9051",  
            "title": "",  
            "isInList": true,  
            "description": "",  
            "altText": "",  
            "galleryImgId": "cccf24be-a78e-486b-ae1c-84c2296be446"  
          },  
          {  
            "siteId": "18e1477c-5056-4853-8951-15268c006a7f",  
            "webId": "d1628f6a-d25e-4641-94cd-2de258f3b1dc",  
            "listId": "{C2DF79CF-273B-4225-9DC4-86A907D46E2F}",  
            "id": "59d95cd0-47fe-42b7-803b-38cfbea2ffd2",  
            "title": "",  
            "isInList": true,  
            "description": "",  
            "altText": "",  
            "galleryImgId": "8af97428-7f0f-42b7-a1db-0f934623e52c"
          }  
        ]

What is the version of the Cmdlet module you are running?

2.2.0

Which operating system/environment are you running PnP PowerShell on?

  • [x] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

leahann avatar Sep 15 '23 22:09 leahann

By using Set-PnPWebPartProperty it's possible to update the galleryImgId from this webpart and give it new value's, but it's not changing the images afterwards or brake things down.

Below the JSON used to play with to change the ImageGallery webpart on a SharePoint Online modern page

{
   "layout":2,
   "carouselSettings":{
      "autoplay":true,
      "autoplaySpeed":5,
      "dots":false,
      "lazyLoad":true,
      "metadata":true,
      "swipe":true
   },
   "gridSettings":{
      "imageSize":2,
      "imageCropping":1,
      "imageAspectRatio":1,
      "lightbox":false
   },
   "imageSourceType":1,
   "isRecursive":false,
   "isCdnEnabledForList":false,
   "hasDynamicModeEnabled":false,
   "maxImagesCount":10,
   "images":[
      {
         "description":"",
         "isInList":true,
         "galleryImgId":"02adfbcc-c31d-4e27-85c0-4ae0e4f873d1",
         "altText":"",
         "imageTileWidth":300
      },
      {
         "description":"",
         "isInList":true,
         "galleryImgId":"02adfbcc-c31d-4e27-85c0-4ae0e4f873d1",
         "altText":"",
         "imageTileWidth":300
      },
      {
         "description":"",
         "isInList":true,
         "galleryImgId":"02adfbcc-c31d-4e27-85c0-4ae0e4f873d1",
         "altText":"",
         "imageTileWidth":300
      },
      {
         "description":"",
         "isInList":true,
         "galleryImgId":"02adfbcc-c31d-4e27-85c0-4ae0e4f873d1",
         "altText":"",
         "imageTileWidth":300
      }
   ],
   "canAlwaysSelectDocLibAsSource":false,
   "layoutComponentId":""
}

If you assign this to a variable in PowerShell and change the value of the galleryImgId to some other valid GUID. It's accepted and afterwards returned by Get-PnPPageComponent.

To change it, make use of the following Set-PnPPageWebPart -Page home -Identity [GUID] -PropertiesJson $test.

So for my opinion you're right that this ID is generated by the webpart itself. I think you need look for an other way around to change the images.

markgort86 avatar May 29 '24 18:05 markgort86