Support

Expand all | Collapse all

Velocity Sort not working

  • 1.  Velocity Sort not working

    Posted 01-19-2020 13:21
    I'm trying to sort a list of documents in Velocity using the following line:

    #foreach( $rcm in $sorter.sort($riskControl, "trace_number"))

    Where riskControl is a list of documents(items) and trace_number is the field of the item type I am trying to sort by. However, it seems that this foreach is skipped when ran in Jama. Does anyone know what could be the issue?

    ------------------------------
    Jack
    ------------------------------


  • 2.  RE: Velocity Sort not working

    Posted 01-20-2020 16:34
    Hi Jack

    I reached out to a Developer Engineer here in Customer support and got some insight into this issue. We can give you a general idea of what it may be, but Velocity is a language created outside of Jama and may be a little out of our scope.

    That being said, our engineers informed me that a VTL foreach loop takes two arguments. The first one is the loop variable and the second is an object that can be iterated over. I'm not 100% sure the second part of the call is a list, $sorter.sort($riskControl, "trace_number")

    You could try storing the sorted riskControl list in a seperate variable to use for the foreach loop.

    We hope this helps at least a bit, but for a more in depth and concrete solution you can reach out to your Account Manager and set up an engagement with our Reports Consultants. They're Jamas Velocity specialists, trained to translate and create custom reports using Velocity.

    Regards


    ------------------------------
    Godiva Hunt
    ------------------------------



  • 3.  RE: Velocity Sort not working

    Posted 01-20-2020 18:36
    Hi Godiva,

    Thanks for the reply. I gave your suggestion a go but I got the same result. I was following the example on the Velocity documentation:

    Single Property Sort
    #foreach($obj in $sorter.sort($objects, "name"))
    $obj.name Ordinal= $obj.ordinal
    #end
    End

    ------------------------------
    Jack
    ------------------------------



  • 4.  RE: Velocity Sort not working

    Posted 01-23-2020 05:49
    Edited by Roman Sickaruk 01-23-2020 05:49
    Hello Jack,

    just an advice from personal experience:

    1. try to use $sortTool not $sorter - $sorter doesn't work for me, but $sortTool yes
    2. if "trace_number" is field inside Document item, you may end up using temporary array, something like:

    #set($helperArray = [])

    #foreach($cDoc in $riskControl)
            #set( $newValue = {
                "trace_number" : $mathTool.toInteger($velocityReportUtil.getValueForField($cDoc, 'trace_number', $dateFormat)),
                "rcm" :  $cDoc
            })
            #if($helperArray.add($newValue)) #end
    #end

    #foreach( $rcmHelper in $sortTool.sort($helperArray, "trace_number"))
             #set($rcm = $rcmHelper.rcm)
            ## process $rcm

    ​​​
    ------------------
    Code like this works fine in my report, but again it is just personal experience hint.

    Kind regards,
    Roman

    ------------------------------
    Roman Sickaruk
    ON Semiconductor
    roman.sickaruk@onsemi.com
    ------------------------------



  • 5.  RE: Velocity Sort not working

    Posted 01-23-2020 07:30
    @Jack



    ------------------------------
    Chloe Elliott
    Jama Software
    Portland OR
    ------------------------------



  • 6.  RE: Velocity Sort not working

    Posted 01-23-2020 12:49
    Hi Roman,

    Thanks for the tips. I'll try them out when I get the chance.

    ------------------------------
    Jack
    ------------------------------