I'm trying to return all possible folders with 'blog-content' in the ID, is there a method for this or a different way of doing this? So far I can only get one result if it is the exact match. Like so:

const ContentSearchModel = require('dw/content/ContentSearchModel');

const apiContentSearchModel = new ContentSearchModel();



const folderSearchResult = apiContentSearchModel.getFolderID();

I can't see any method for returning an array of folders matching the query:

enter image description here


So i think this may be possible a different way - by content searching all articles with say 'article' in the id and then using the getMatchingFolders method in the contentSearchRefinements class to output the collection of folders. Although now i don't really understand how to run the returned articles through the refinement class. any help would be appreciated?


You're on the right track using ContentSearchModel. If the folder called blog-content is a parent folder for all the other folders that have blog-content in their IDs then you should be able to achieve what you want using the recursive search feature. I also would assume that a Folder Refinement is configured in Business Manager on the root of the library. eg:

A screenshot illustrating the location and sample configuration of a Folder Content Search Refinement in Salesforce Commerce Cloud B2C's Business Manager application

If so, the first thing you'll want to do is ensure you're also setting the recursiveFolderSearch flag to true before calling search(). eg:


You should be able to then get a collection of the search refinements using:

var refinements = apiContentSearchModel.getRefinements();

Once you've acquired a collection of available refinements, you'll want to call:

var folderRefinement = refinements.getFolderRefinementDefinition();

Now that you have a reference to the FolderRefinementDefinition you can now get the refinement values associated with it. Those will be the folders where content search hits were found. You can get them using:

var folders = refinements.getRefinementValues(folderRefinement);

folders is now a collection of ContentSearchRefinementValue objects. Each of which would have a getValue() method which should be the ID of the folder. You can get the displayName of the folders using getDisplayValue(). You can also get the number of assets included in that folder that match the search using the getHitCount() method.

Keep in mind that if you have multiple levels of these folders that the getHitCount() method would reflect any sub-folders as well.

  • ha amazing thank you! just noticed you work at astound.. im trying to make changes to a system built by astound funnnily enough! – alecbaldwin Dec 20 '19 at 10:09
  • wooop made it work, legend! – alecbaldwin Dec 20 '19 at 12:41
  • just one question: how come there is a global value in the folders collection? – alecbaldwin Dec 20 '19 at 12:42
  • @alecbaldwin I'm not sure what you mean by a global value in the folders collection. Can you share a screenshot or more detailed description? – sholsinger Dec 23 '19 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.