3

I'm trying to sort the IComponent list by a "Field Value" in the component using ExtendedQueryParameters, but by default the QuerySortField is assigned with default value. Help me to sort with other fields in the component.

Example, I want to sort the list by date field in the component.

How can I change this QuerySortField,

public ExtendedQueryParameters()
{
    // Default all parameters
    QuerySchemas = new string[]{};
    MetaQueryValues = new List<MetaQueryItem>();
    MetaQueryLogic = QueryLogic.AllCriteriaMatch;

    KeywordValues = new List<KeywordItem>();
    KeywordQueryLogic = QueryLogic.AllCriteriaMatch;

    LastPublishedDate = DateTime.MinValue;

    **QuerySortField = "ItemTitle";**
    SortType = MetaSortFieldType.STRING;
    SortType = MetaSortFieldType.DATETIME;
    QuerySortOrder = MetaQueryOrder.Ascending;
    MaximumComponents = int.MaxValue;
}
2

QuerySortField is public property, you can update the value.

but i think you can have only fields of type SortColumn(ItemCreationDate, ItemMajorVersion, many more) from Tridion.ContentDelivery.DynamicContent.Query.SortParameterclass and Meta data Field of your component, if date field in your question is meta datafield you can get result as per your requirement, but with non-metaField its not possible. You can also update that field to MetaData field.

var parameters = new ExtendedQueryParameters();
parameters.QuerySortField = "YourcustomMetaField"; 
parameters.SortType = ExtendedQueryParameters.MetaSortFieldType.DATETIME; parameters.PublicationId = publicationID; 
parameters.QuerySchemas = new[] { schemaId }; 
parameters.FindComponents(queryparameters);

you can also try CD API

var publicationCriteria = new PublicationCriteria(publicationId);
var itemScemaCriteria = new ItemSchemaCriteria(SchemaTcmUri.ItemId);
var customMetaKeyCriteria = new CustomMetaKeyCriteria("MetaIssueDate", Criteria.Equal);
Criteria[] finalCriteria = { publicationCriteria, itemScemaCriteria, customMetaKeyCriteria};
var query = new Query(CriteriaFactory.And(finalCriteria));
var customMetaKeyColumnDate = new CustomMetaKeyColumn("MetaIssueDate", MetadataType.DATE);
var sortParameter = new SortParameter(customMetaKeyColumnDate, SortParameter.Descending);
query.AddSorting(sortParameter);
var result = query.ExecuteQuery();
  • am able get the sort by the Metadata field but i want this to combine with Keyword filter and Mate data sort. below code is giving error. var queryParameters = new ExtendedQueryParameters(); string[] schemas = { SchemaUri }; queryParameters.QuerySchemas = schemas; queryParameters.PublicationId = ID; queryParameters.KeywordValues = keys; queryParameters.QuerySortField = "date"; queryParameters.SortType =ExtendedQueryParameters.MetaSortFieldType.DATETIME; FindComponents(queryParameters) – Balajhi SV Aug 5 '14 at 10:39
  • is this keyword part of metadata? – Raj Kumar Aug 5 '14 at 11:16
  • keywords are not part of Metadata; if this can be resolved by moving to meta i can move it. please provide more details on the code for keyword filter in metadata.. – Balajhi SV Aug 5 '14 at 12:52
  • 1
    if its part of metadata, normal metadata query should work just provide the "xmlname" of that metafield in the query – Raj Kumar Aug 5 '14 at 14:47
  • any other way if the keyword is not in meta data... – Balajhi SV Aug 5 '14 at 16:55

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.