Search code examples
xmlsortinggenexus

SDT sort by numeric field


I have a SDT with a collection and it comes from a XML sent by the customer. Sometimes they send the items in a wrong order, like inverse, so I have to sort it. But the sort function in Genexus sorts byte by byte instead of numeric and when the collection is bigger than 10 items it results as:

<sdt>
    <field1>something</field1>
    <colection>
        <item>
            <itemcode>1</itemcode>
            <itemDescription>ITEM 1</itemDescription>
        </item>
        <item>
            <itemcode>10</itemcode>
            <itemDescription>1ITEM 10</itemDescription>
        </item>
        <item>
            <itemcode>2</itemcode>
            <itemDescription>ITEM 2</itemDescription>
        </item>
        <item>
            <itemcode>20</itemcode>
            <itemDescription>ITEM 20</itemDescription>
        </item>
    </collection>
</sdt>

How could I sort it respecting the numerical order?


Solution

  • Thank you Sandro.

    I think the reason of ordering byte by byte is because the type of the field in the SDT is string. Probably if the field would be integer, Genexus would order corectly. It needs to be careful changing the filed's type because it's used in a web service, so it could break third party integrations, but I'll analyse the viability.