Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Load Contexthub on conditional basis

yashaswidotiya
Level 2
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
BrianKasingli
Correct answer by
Community Advisor
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
BrianKasingli
Correct answer by
Community Advisor
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

yashaswidotiya
Level 2
Level 2
Thank you for answer.I tried above solution but still I am getting console error.
BrianKasingli
Community Advisor
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 

yashaswidotiya
Level 2
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.