2

I am trying to get all components based on the schema, I have to ignore one particular tcm ID from the query. as i already have the component object in code. i am unable to do it.

This is my code now

AndCriteria totalCriteria = null;//this will be used for combining all kind of criteria 
PublicationCriteria pubCriteria = new PublicationCriteria(myPublicationId);
ItemSchemaCriteria IsFVideSchema = new ItemSchemaCriteria(MySchemaID);
ItemTypeCriteria IsComponent = new ItemTypeCriteria(16);

//Here i want to include one more critera, so that ignore this TCM ID ("tcm:mypub-ItemId-16); 
//I want to get all the recent components by schema, it's working fine. But i already have one of component via component presentations //earlier, because of this reason i have to get top 4 components, but query including the one which i already have. 


TaxonomyKeywordCriteria taxonomyKeywordCriteria = new TaxonomyKeywordCriteria(catgoryId, keyWordId, false);
SortParameter sortParameter = new SortParameter(SortParameter.ItemLastPublishedDate, SortParameter.Descending);

totalCriteria = new AndCriteria(pubCriteria, IsFVideSchema );
totalCriteria = new AndCriteria(totalCriteria, IsComponent);
totalCriteria = new AndCriteria(totalCriteria, taxonomyKeywordCriteria);
query.Criteria = totalCriteria;
query.AddSorting(sortParameter);
PagingFilter Pagefilter = new PagingFilter(0, limit); //limit is 4 here
query.SetResultFilter(Pagefilter);
string[] ItemUris = query.ExecuteQuery();

Please can anyone help me ?, I just want to get the 4 components excluding this tcm ID. I have to ignore the component in Tridion Query, or else i will get the same component back again. Is there any way ?

1

To achieve the desired result you should use following two additional conditions:

  1. LimitFilter - To limit no of components to 4
  2. NotInCriteria - To exclude the component that you already have.

Let me know if you are still facing any issues.

Updated code will be something like:

AndCriteria totalCriteria = null;//this will be used for combining all kind of criteria 
PublicationCriteria pubCriteria = new PublicationCriteria(myPublicationId);
ItemSchemaCriteria IsFVideSchema = new ItemSchemaCriteria(MySchemaID);
ItemTypeCriteria IsComponent = new ItemTypeCriteria(16);

//Here i want to include one more critera, so that ignore this TCM ID ("tcm:mypub-ItemId-16); 
//I want to get all the recent components by schema, it's working fine. But i already have one of component via component presentations //earlier, because of this reason i have to get top 4 components, but query including the one which i already have. 
NotInCriteria notInCriteria = new NotInCriteria("<your component details>")

TaxonomyKeywordCriteria taxonomyKeywordCriteria = new TaxonomyKeywordCriteria(catgoryId, keyWordId, false);
SortParameter sortParameter = new SortParameter(SortParameter.ItemLastPublishedDate, SortParameter.Descending);

totalCriteria = new AndCriteria(pubCriteria, IsFVideSchema );
totalCriteria = new AndCriteria(totalCriteria, IsComponent);
totalCriteria = new AndCriteria(totalCriteria, taxonomyKeywordCriteria);
totalCriteria = new AndCriteria(totalCriteria, notInCriteria);

query.Criteria = totalCriteria;
query.AddSorting(sortParameter);
LimitFilter limitfilter = new LimitFilter(4); //limit is 4 here
query.SetResultFilter(limitfilter);
string[] ItemUris = query.ExecuteQuery();

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.