SOLVED

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

Go to solution
nwarr
Level 2

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

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
2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

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

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

 

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

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

${number.format("${esc.h}.00",$Campaign.Amount_Allocated_Percent_Change)}

View solution in original post

5 REPLIES 5
SanfordWhiteman
Level 10 - Community Moderator

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

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

 

nwarr
Level 2

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

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
Level 10 - Community Moderator

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

${number.format("${esc.h}.00",$Campaign.Amount_Allocated_Percent_Change)}
nwarr
Level 2

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

Thank you -- as a new Marketo user (also new to VTL) your resources and your knowledge have been invaluable.

SanfordWhiteman
Level 10 - Community Moderator

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

Happy to help.