Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Load Contexthub on conditional basis

Avatar

Level 2

Hi All,

 

I want to load custom contexthub store on basis of some condition and for that, I have used apply method while registering the storeCandidate. The issue here is that I am getting "no suitable store Implementation found for ...." if condition fails. 

Is there any way that I can prevent these error from coming ?

Sample Code:- 

contextHub.Utils.storeCandidates.registerStoreCandidate(
"VariableName",
"contexthub.storeName",
0,

function(){return false};
);

 

Error message -- No suitable store implementation found for type: contexthub.storeName

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@yashaswidotiya,

Sure, you can do this with a JavaScript condition block before you run the "registering the store candidate".

 

   function registerStoreCandidate() {
      if (canRegisterStoreCandidate()) {
        contextHub.Utils.storeCandidates.registerStoreCandidate(
        "VariableName",
        contexthub.storeName,
        0)
      }
   }

   function canRegisterStoreCandidate(){
     // ...someLogicReturnsBoolean;
     // example: returns true if window.contexthub && window.contexthub.storeName both are not empty or undefined.
     return window.contexthub && window.contexthub.storeName;
   };

 

 

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

@yashaswidotiya,

Sure, you can do this with a JavaScript condition block before you run the "registering the store candidate".

 

   function registerStoreCandidate() {
      if (canRegisterStoreCandidate()) {
        contextHub.Utils.storeCandidates.registerStoreCandidate(
        "VariableName",
        contexthub.storeName,
        0)
      }
   }

   function canRegisterStoreCandidate(){
     // ...someLogicReturnsBoolean;
     // example: returns true if window.contexthub && window.contexthub.storeName both are not empty or undefined.
     return window.contexthub && window.contexthub.storeName;
   };

 

 

 

Avatar

Level 2
Thank you for answer.I tried above solution but still I am getting console error.

Avatar

Community Advisor

Try this:

function createSimplePersistedStore() {
  if (!window.ContextHub) return;
  let myStoreCandidate = function(){};
  ContextHub.Utils.inheritance.inherit(myStoreCandidate,ContextHub.Store.PersistedStore);
  if (myStoreCandidate != undefined || myStoreCandidate != null) {
       ContextHub.Utils.storeCandidates.registerStoreCandidate(myStoreCandidate,
       'contexthub.mystorecandiate', 0);
   }
}

https://helpx.adobe.com/uk/experience-manager/6-3/sites/developing/using/ch-extend.html 

Avatar

Level 2

I have total 5 custom stores out of which 4 should be loaded on all pages while 1 should load only on some specific pages. If I use above solution, my store does not get loaded but I am adding an additional console error as my store is not registered but it is present in conf directory and it is in enabled state. So, if possible, is there a way to make property changes through code where I can disable store based on some logic. Java code will also work.