dakaspbe
New Creator

Edit content page with API

Hi,

I want to edit a content page within a Beanshell script using the API.

This is the script part I tried:

 if (!page.isLocked()) {
   page.setLock(true, true);
}
 
...
page.setFormData(formData);
page.save();
page.release();
page.setLock(false, false);
 

Currently I get the following Error when I try to lock the page in the first step:

Target exception: java.lang.UnsupportedOperationException: lock is not supported for release store elements

Does anybody why this Exception occurs and how I can avoid it.

Or is there another way to edit the page?

Thanks in Advanced

0 Kudos
3 Replies
Peter_Jodeleit
Crownpeak employee

The page element is from the release store, which is read-only. Only elements from the current store can be edited.

Peter
0 Kudos
dakaspbe
New Creator

Hi,

thanks for the quick answer. How can I select the element of the correct current store?

Currently my workflow is as follows:

1. First find a specific template:

StoreElementAgent sea = context.requireSpecialist(StoreElementAgent.TYPE);
template = sea.loadStoreElement(TEMPLATE_UID, SectionTemplate.UID_TYPE, false);

2. Find all usages of this template:

template.getIncomingReferences()

3. select the parent-page for each reference

section = ref.getReferencedElement();
page = section.getParent().getParent();

 

Unfortunately these pages are always in the release store (page.isInReleaseStore() returns true).

How can I edit the pages? What am I doing wrong?

Kind regards

Bernadette

0 Kudos
mbergmann
Crownpeak employee

Hi,

the „isInReleaseStore()“ does not tell if the element is FROM the release store but (just) if that node (also) exists there. AFAIR It will only return false for never released elements.

It should help to check the ReferenceEntry itself whether it points to an element from the releaseStore and ignore those:

ref.getRelease()

Michael

0 Kudos