5

I would like to filter the results from an Anguila WhereUsed query to return only Components based on a certain schema. But, when I specify the ItemType or BasedOnSchema filters it returns no results. Why do the filters not work?

The code is based on Jaime's solution here: WhereUsed with Tridion Anguilla GUI Framework

Update: I have included my attemp to use a callback on the load method, but not sure if it is correct...

function ShowWhereUsed(c){
    // Begin Where Used
    //Get the item:
    $item = $models.getItem(c.getId()); 

    //Define a filter:
    $filter = new Tridion.ContentManager.ListFilter();
    $filter.columns = $const.ColumnFilter.DEFAULT;
    $filter.conditions.InclLocalCopies = true; 
    //$filter.conditions.ItemTypes = 16;    
    //$filter.conditions.BasedOnSchema = "tcm:174-277968-8";  // specifying a schema returns no results

    console.log('Before Load');
    //Get the list:
    $list = $item.getListUsingItems($filter, false, false);

    // register onload event for this item
    $evt.addEventHandler($list, "load", onItemLoaded);

    // call to load the item
    $list.load($list.isLoaded(true));
    //$list.load(true);

    console.log('After load');
}   

 // define onload delegate method
var onItemLoaded = function onItemLoaded() {
    console.log('onItemLoaded start');
    $evt.removeEventHandler(this, "load", onItemLoaded);

    // continue your code here
    var listXmlDoc = this.getXmlDocument();
    console.log(listXmlDoc);    
    ShowWhereUsedDisplayLinks(listXmlDoc);

    console.log('OnItemLoaded end');
};

With the below code (workaround, prefer to use above) I can get only Components, but then I also need to test for the Schema:

var tridionItem = $models.getItem(compUri);
console.log(tridionItem);
var itemType = tridionItem.getInfo().ItemType;

if (itemType == $const.ItemType.COMPONENT)
{
    // Test for Schema here and show
}
  • 2
    Are you sure your list is loaded and not using a cached version which might not have your filter? I would recommend using the load event handler to make sure your list is fully loaded, see my example in this answer. – Bart Koopman Dec 5 '13 at 11:46
  • Hi Robert, will take a look, just a comment, I use "global" variables because I do my tests in the browser, but you should define them as local, for example $list, $item and $filter I would define as local, i.e., without the $ sign and with the "var" modifier before. Will try to check the Filtering capabilities. – Jaime Santos Alcón Dec 5 '13 at 15:27
3

I just modified your function a little bit as follows:

function ShowWhereUsed(itemUri, itemTypes, basedOnSchemas){
// Begin Where Used
//Get the item:
var item = $models.getItem(itemUri); 

//Define a filter:
var filter = new Tridion.ContentManager.ListFilter();
filter.columns = $const.ColumnFilter.DEFAULT;

//These are all the available conditions
//      ItemTypes: undefined,           // array of strings
    //      SubType: undefined,             // number
    //      LockFilter: undefined,          // Tridion.Constants.LockType
    //      LockResult: undefined,          // Tridion.Constants.LockType
    //      LockUser: undefined,            // user uri string
    //      Recursive: undefined,           // boolean
    //      SchemaPurpose: undefined,       // array of Tridion.Constants.SchemaPurpose
    //      ShowNewItems: undefined,        // boolean
    //      BasedOnSchema: undefined,       // array of uri strings 
    //      HideActiveDirectory: undefined, // boolean
    //      NoPredefined: undefined,        // boolean
    //      RelatedTo: undefined,           // array of uri's
    //      OnlyLatestVersions,             // boolean
    //      InPublication,                  // uri string
    //      InclLocalCopies,                // boolean
    //      InclParentItem,                 // boolean
    //      InclExternalLinks,              // boolean
    //      Enumeration,                    // string
    //      InfoType,                       // number, Model.getListPublishTransactionStates()
    //      StartDate,                      // Date
    //      EndDate,                        // Date
    //      User,                           // user uri string
    //      Publication,                    // publication uri string
    //      PublicationTarget,              // publication target uri string
    //      Priority,                       // number, Model.getListPublishPriorities()
    //      Abstract,                       // boolean, for Keywords
    //      Descendant,                     // boolean, for ListClassifiedItems
    //      ResultLimit                     // number, for ListClassifiedItems
    //      BasedOnItem: undefined,         // array of uri strings
    //      IncludeActiveProcesses          // boolean, for ListClassifiedItems
    //      DSGroupName                     // string, for ListDirectoryServiceTestUsers
    //      DSGroupSearchDN                 // string, for ListDirectoryServiceTestUsers
    //      DSGroupSearchType               // string, for ListDirectoryServiceTestUsers
    //      NSUserType                      // number, for ListNonSystemUsers
    //      NSUserName                      // string, for ListNonSystemUsers
    //      NSDomainName                    // string, for ListNonSystemUsers
    //      ItemIds                         // array, for SystemWideList

    //      ActivityState                   // number, for GetListActivityInstances
    //      IncludeAdditionalDateColumns    // boolean, for GetListActivityInstances
    //      IncludeWorkItems                // boolean, for GetListActivityInstances
    //      ForAllUsers                     // boolean, for GetListActivityInstances
    //      InclOnlyWorkflowBundles         // boolean, for GetListContainingBundles

    //      BluePrintItemId                 // string, for List which can contain Publications

filter.conditions.InclLocalCopies = true; 
filter.conditions.ItemTypes = itemTypes; //["16"] array of types   
filter.conditions.BasedOnSchema = basedOnSchemas; //["tcm:25-2816-8"] array of uris  
filter.conditions.OnlyLatestVersions = true;
//This is optional, depending on whether you wanna filter by the "owning" publication
filter.conditions.InPublication = item.getPublicationId();

var list = item.getListUsingItems(filter, false, false);


//Handler on load
var onItemLoaded = function onItemLoaded() {    
    $evt.removeEventHandler(list, "load", onItemLoaded);
    // continue your code here
    var listXmlDoc = list.getXmlDocument();
    var xml = list.getXml();
    console.debug(xml);
    console.debug(listXmlDoc);    
    //ShowWhereUsedDisplayLinks(listXmlDoc);

};

// call to load the item
if(!list.isLoaded()){
    // register onload event for this item
    $evt.addEventHandler(list, "load", onItemLoaded);
    list.load(list.isLoaded(true));
}else{
    onItemLoaded();
}    
}   

Then you can call it with something like this:

ShowWhereUsed("tcm:1-234", ["16"], ["tcm:1-235-8"]);

Note: the filter by Schema uri doesn't seem to work very well, but the item type does indeed work.

Let me know what you think.

  • I agree the SchemaFilter doesn't seem to work, but the rest works great! Thanks for the extra conditions such as OnlyLatestVersion and InPublication. – robrtc Dec 5 '13 at 16:17
3

I think your main problem now is in the definition of your filter. You try to set the conditions as properties, but they are mostly arrays I believe. See for instance the following examples which I got from the CME js files:

var templateFilter = new Tridion.ContentManager.ListFilter(
{ 
    conditions: 
    { 
        ItemTypes: [ itemType ] 
    } 
});

or you could also set them like this:

var filter = new Tridion.ContentManager.ListFilter();
filter.conditions.ItemTypes = [
    $const.ItemType.FOLDER,
    $const.ItemType.VIRTUAL_FOLDER
];

The Based On Schema seems to be set like this:

filter.conditions.BasedOnSchema = options.basedOnSchema;

Where options.basedOnSchema holds the full TCM URI of a Schema it appears.

For more examples do a find in files in your ..\Tridion\web\WebUI\Editors\CME folder and see where Tridion.ContentManager.ListFilter is used for example.

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.