winod
I'm new here

How to get the id of the current preview section in Value Service?

Hi there,

   I have a ValueService to check if there is any duplicate values in the sections .I want to find out the id of the

previewed section element. Is there any Api to find out this long id? 

Thanks ,

Vinod

0 Kudos
3 Replies
phillip_austerf
New Creator

Hi Vinod,

the current preview section id can be obtaind via

$CMS_VALUE(#global.section.id)$

However, which duplicates do you want to identify? Each secion of a page has its unique id, so even if the values are equal (i.e. duplicates), the id's will still be different.

Anyway, to obtain the section ids via the api, this might be a good starting point:

String sUid = "my-uid";
String sPageContentContainer = "Content right";

PageStoreRoot pPageStore = (PageStoreRoot) pProject.getUserService().getStore(Store.Type.PAGESTORE, false);
Page pPage = (Page) pPageStore.getStoreElement(sUid, IDProvider.UidType.PAGESTORE);

Body pBody = pPage.getBodyByName(sPageContentContainer);
Listable vpSections = pBody.getChildren(Section.class);

for (Section _sec : vpSections)
{
    System.out.println("Current section: " + _sec.getDisplayName(null));
    System.out.println("Current section id: " + _sec.getId());
}

Cheers,

Phillip.

0 Kudos

Hi Phillip,

       Thanks for replying to my query.

             I have a page that has multiple sections .Each section form has input text for entering "key" and another input text for entering "value". I have to ensure no duplicate keys are entered in the page . So a value service is written that is triggered on entering "key" upon editing section . The value service will check if there is any duplicates in the sections.

        To ensure the value service don't compare the same section, i want to pass the current edited section id as commented in the below rules ( key here is st_formfields_id) . A defect in Firstspirit is not allowing to use #global.id . So is there any other way to programmatically retrieve the current edited section id  in the value service?

<ON_SAVE>

          <SCHEDULE service="DataValueService" id="check_duplicates" delay="100">            

                    <PARAM name="SERVICE_ACTION">               

                              <TEXT>VALIDATE_ITEM_ID</TEXT>           

                    </PARAM>        

                    <PARAM name="ITEM_ID">               

                              <PROPERTY source="st_formfields_id" name="VALUE"/>           

                    </PARAM>

      <!--<PARAM name="CURRENT">               

                              <PROPERTY source="#global.id" name="VALUE"/>           

                    </PARAM> -->

          </SCHEDULE>

          <DO>    

                    <VALIDATION>     

                              <PROPERTY source="st_formfields_id" name="VALID"/>     

                              <MESSAGE lang="*" text="Duplicate ItemId found.ItemId should be unique."/>    

                    </VALIDATION>   

          </DO>

</ON_SAVE>

0 Kudos

Hello Vinod,

is this still an open question? Do you need further help or did the given answer already help you? If so, it would be great, if you mark the reply as correct answer.

If you have found a solution by yourself, it would be very kind, if you post it here.

Best regards

Michaela

0 Kudos