# Updating imagesets through script

**URL:** <https://community.bloomreach.com/t/updating-imagesets-through-script/4091>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [August 24, 2023, 8:19am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091 "2023-08-24T08:19:51Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ineke](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/ineke/32/1401_2.png) [@Ineke](https://community.bloomreach.com/u/Ineke)\
**Post date:** [August 24, 2023, 8:19am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/1 "2023-08-24T08:19:51Z")

</div>

Hello, I have created a new image set on my local environment following the instructions here: [Configure Image Variants - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS](https://xmdocumentation.bloomreach.com/trails/developer-trail/configure-out-of-the-box-features/configure-image-variants.html) and added small/medium/large image sizes. On my local environment this worked very well, all images were updated with the new sizes.

Now I have deployed these changes to our staging environment which contains other images than the local environment. I thought it would be enough to update the existing images by running the UpdateImageSets script(which was also generated automatically when creating the new imageset) through the updater editor but this doesn’t seem to change anything. Is there anything else I should do to make this work? Or should I update the script myself? I couldn’t find anything about this in the documentation.

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [August 24, 2023, 8:44am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/2 "2023-08-24T08:44:15Z")

</div>

That script should update images with new definitions in that image set, it won’t change the image set.

So an image A, is of type hippogallery:imageset. If you add a new variant to hippogallery:imageset then the script will update the image. But if you make a new imageset myproject:imageset, then the image A won’t have it’s type changed, so will be unaffected by the new imageset.

---

<div class="post-metadata">

**Author:** ![Ineke](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/ineke/32/1401_2.png) [@Ineke](https://community.bloomreach.com/u/Ineke)\
**Post date:** [August 24, 2023, 9:01am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/3 "2023-08-24T09:01:11Z")

</div>

Hmm, but then why did it update the existing images on my local environment? I have now added a new image in the staging environment, but it also doesn’t create the small/medium/large sizes for that one.

So would you say that if I want to update all images on our staging&production environment, I have to create a script myself to set their imageset type to our custom imageset?

---

<div class="post-metadata">

**Author:** ![Ineke](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/ineke/32/1401_2.png) [@Ineke](https://community.bloomreach.com/u/Ineke)\
**Post date:** [August 24, 2023, 9:03am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/4 "2023-08-24T09:03:21Z")

</div>

Ohh, I see now that in the console, on the folder for the images, the `hippostd:gallerytype` is set to `hippogallery:imageset`. So I should probably set that one to our custom imageset type right?

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [August 24, 2023, 9:41am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/5 "2023-08-24T09:41:40Z")

</div>

That will work for creating new imagesets, but the existing ones will still be of the old type. You will have to make an updater to change the type of the old imagesets.

---

<div class="post-metadata">

**Author:** ![Ineke](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/ineke/32/1401_2.png) [@Ineke](https://community.bloomreach.com/u/Ineke)\
**Post date:** [August 24, 2023, 11:29am UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/6 "2023-08-24T11:29:29Z")

</div>

Okay thanks, I will try that!

---

<div class="post-metadata">

**Author:** ![Ineke](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/ineke/32/1401_2.png) [@Ineke](https://community.bloomreach.com/u/Ineke)\
**Post date:** [August 24, 2023, 3:15pm UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/7 "2023-08-24T15:15:43Z")

</div>

For future reference and if anybody else bumps into the same issue, here is the script, just set your own imageset type in the parameters. After running this script, your can run the UpdateImageSets scripts and it will create the new sizes for you:

```auto
import org.onehippo.repository.update.BaseNodeUpdateVisitor

import javax.jcr.Node
import javax.jcr.RepositoryException

/**
 * Groovy script to update the primary type of all imagesets to a new primary type
 *
 * XPath query: content/gallery//element(*, hippogallery:imageset)
 *
 * Parameters: { "primaryType": "yournamespace:yourimageset" }
 */
class ConvertImageSetTypeUpdater extends BaseNodeUpdateVisitor {

    boolean doUpdate(Node node) {
        String newPrimaryType = this.parametersMap["primaryType"]
        String nodeName = node.getName()

        log.debug(String.format("Attempting to update primary type of node %s from %s to %s", nodeName, node.getPrimaryNodeType().getName(), newPrimaryType));
        try {
            if (node.getPrimaryNodeType().getName() != newPrimaryType) {
                node.setPrimaryType(newPrimaryType);
                log.debug(String.format("Primary type of node %s updated to %s", nodeName, newPrimaryType));
            } else {
                log.debug(String.format("Primary type already set to %s", newPrimaryType));
            }
        } catch (RepositoryException e) {
            log.error(String.format("Could not update primary type of node %s to %s", nodeName, newPrimaryType), e)
            node.getSession().refresh(false/*keepChanges*/)
        }
    }

    @Override
    boolean undoUpdate(final Node node) throws RepositoryException, UnsupportedOperationException {
        return false
    }
}

```

---

<div class="post-metadata">

**Author:** ![Ilakkia\_Baskar](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/ilakkia_baskar/32/2044_2.png) [@Ilakkia\_Baskar](https://community.bloomreach.com/u/Ilakkia_Baskar)\
**Post date:** [May 20, 2025, 4:16pm UTC](https://community.bloomreach.com/t/updating-imagesets-through-script/4091/8 "2025-05-20T16:16:57Z")

</div>

Hello @Ineke ,

We are happy you are part of Bloomreach Developer’s Community.  
Thank you for reaching out to us.  
We hope we have answered your queries and therefore marking this thread for Closure.  
We are delighted to acknowledge your ongoing contributions to our esteemed Bloomreach Community.

Best Regards,  
Bloomreach
