Custom Object Sorting by Float field -- fails without decimals or when null | Community
Skip to main content
New Participant
September 12, 2022
Solved

Custom Object Sorting by Float field -- fails without decimals or when null

  • September 12, 2022
  • 1 reply
  • 2391 views

This may be somewhat related to the old "Sorting Weirdness" thread, but it didn't provide a clear answer and I'm hoping I might be able to find a solution.

We are building a report from a custom object. One of our fields uses a float data type, and we need to be able to sort by that field.

  • If any one of the fields has a null value, the entire report fails to display. (We have since solved for null values)
  • If any of the values contains no decimal places, the entire report fails to display.
  • If we remove the $sorter.sort() functionality, the report displays, though it is not ordered correctly.
  • Our input source data contains 2 decimal spaces for all values, but upon import, when these spaces contain '0', Marketo automatically drops them. (10.50 becomes 10.5, 10.00 becomes 10) Is there any way to force these values to contain 2 decimal spaces prior to sorting?
#foreach( $object in $sorter.sort($list_cList, "Send_Date:desc"))
  #if( $foreach.count > 1 )
    #break
  #end
  #set ($maxDate = $object.Send_Date)
#end

#set( $qualifyingCampaigns = [] )
#foreach( $Campaign in $list_cList )
  #if( $Campaign.Campaign_ID.equals("FILTER_VALUE_A") && $Campaign.Send_Date.equals($maxDate) )
    #set( $void = $qualifyingCampaigns.add($Campaign) )
    #set( $CID = $Campaign.Campaign_ID )
  #end
#end

#if( $CID.equals("FILTER_VALUE_A"))

  ## Display list items - If Amount_Allocated_Percent_Change is null or does not contain decimal, report will not display
  #foreach( $Campaign in $sorter.sort($qualifyingCampaigns, "Amount_Allocated_Percent_Change") )

    <tr>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">$Campaign.Policy_Number</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">$Campaign.Policy_Annuitant</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">$Campaign.Allocation_Option</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">$Campaign.Next_Anniversary</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">$Campaign.Amount_Allocated_Percent_Change%</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">
      #if($Campaign.Percent_Cap_Change)$Campaign.Percent_Cap_Change%#end</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">
      #if($Campaign.Upper_Lock)$Campaign.Upper_Lock%#end</td>
      <td style="border: 1px solid #dddddd; padding: 6px; line-height: 1.5; text-align: center; vertical-align: middle;">
      #if($Campaign.Lower_Lock)$Campaign.Lower_Lock%#end</td>
    </tr>
  #end

#end
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Cause is clear, Double.compareTo() doesn’t have an overload for Integer.

 

Convert all the Integers to Doubles before sorting:

#foreach( $Campaign in $list_cList ) #set( $Campaign.Amount_Allocated_Percent_Change = $convert.toDouble($Campaign.Amount_Allocated_Percent_Change) ) #end

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
September 12, 2022

Cause is clear, Double.compareTo() doesn’t have an overload for Integer.

 

Convert all the Integers to Doubles before sorting:

#foreach( $Campaign in $list_cList ) #set( $Campaign.Amount_Allocated_Percent_Change = $convert.toDouble($Campaign.Amount_Allocated_Percent_Change) ) #end

 

NickWa7Author
New Participant
September 15, 2022

This is great, thank you. One further question, the whole numbers only display with one decimal point (18 becomes 18.0) -- is there a quick method to ensure all numbers display with two decimal points?

SanfordWhiteman
New Participant
September 15, 2022
${number.format("${esc.h}.00",$Campaign.Amount_Allocated_Percent_Change)}