Sorting items in SDIM/VTL descriptions

Hello, we have IdentityNow and currently use SDIM for Service Now. I was hoping someone knew how to sort the list of items in the $request object using VTL syntax. It would seem that perhaps we would need to add something like this to the beforeprovisioningrule
VelocityContext velocityContext = new VelocityContext(variableMap);
velocityContext.put(“sorter”, new SortTool());

and then in the VTL something like this
#foreach($item in $request.items)
#if($item.name == ‘groups’)
#set($groupList = $item.value)
#if ($groupList.size()>0)
#foreach($grp in $sorter.sort($groupList))
$grp$newline
#end
etc

Has anyone done anything similar or know if I’m on the right track with my approach? Specifically, where/how I need to add the VelocityContext object. I hoped that perhaps spTools would contain the methods I need but I don’t believe it does. Thank you.