But to simplify, say you want to sort ascending or descending on a certain field.

Branch your script.

If [$$sort.direction = "ASC"]

Sort Records [//sort ascending]

Set Variable [$$sort.direction; "DES"]

Else

Sort Records [//sort descending]

Set Variable [$$sort.direction; "ASC"]

End If

You can also create a field in the table used just for sorting and pass the script parameter to that field name. Then in the script you would just sort by that name, branching for ascending and descending.