Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
azimabadi
Creator III
Creator III

Sorting a Field

HI All,

I have a small table :

LOAD * Inline [

FieldA, FieldB, FieldC

  100, B, 5

  200, E, 4

  300, A, 3

  400, D, 2

  500, C, 1

];

and i have a simple macro :

SUB testSort

  set fld = ActiveDocument.Fields("FieldA")

  set fldsrt = fld.GetDefaultSortCriteria

  fldsrt.SortByAscii = 0

  fldsrt.SortByFrequency = 0

  fldsrt.SortByLoadOrder = 0

  fldsrt.SortByNumeric = 0

  fldsrt.SortByState = 0

  fldsrt.SortByExpression = 1

  fldsrt.Expression.v = "Ord(FieldB)"

  fld.SetDefaultSortCriteria fldsrt

  set val = fld.GetPossibleValues

  for i=0 to val.Count-1

    msgbox(val.Item(i).Text)

  next

END SUB

i expect(need) to get the message box in the order of FieldB :

300, 100, 500, 400, 200

but this code dosn't go as i run.

i have attached the sample file too.I will appreciate any help.

Best Regards

Peyman

5 Replies
azimabadi
Creator III
Creator III
Author

It seems that in macro, the sort order ist original "Load Order" and setting the sortCriteria affects only the objects that put on interface after runing of macro.

deepakk
Partner - Specialist III
Partner - Specialist III

hi Peyman,

Instead of taking the value from the field, try to take the value from a field. It will be much easier.

I hope the attach  sample helps you out.

Deepak

azimabadi
Creator III
Creator III
Author

Thank you Deepak,

It's really intersting way. I mark your answer as "Helpful" so other people can see my problem and give suggestions. When i get no other and better answer i will mark it as "Correct Answer".

Best Regards

Peyman

jagan
Partner - Champion III
Partner - Champion III

Hi Peyman,

You can also do this by using Dual() in script.  Check attached file for solution.

Regards,

Jagan.

azimabadi
Creator III
Creator III
Author

Thank you Jagan,

I Think this a better way, because i don't neet to defeine a order Expression.

Best Regards

Peyman