Tips   >   Lists   >   Lists Sendall

Lists Sendall

$sendall

is a powerful Omnis Studio method which can pack a lot of code into a single line.

For the first few years that I worked with Omnis Studio $sendall was intimidating to me. I had trouble following the syntax and didn't see many (any?) examples in the documentation on how to use it. $sendall experts on the Omnis Developers List like Tim Stewart, Weitse Jacobs, and Reg Paling would amaze me with some of the complex sendalls they would post on the Omnis underground list server. Since I didn't clearly understand $sendalI I generally avoided using it.

There is a concern among developers that if you go overboard with the use of $sendall in your code others will have a hard time understanding and maintaining your code. You can't step through a $sendall the way you can step through a loop. It either works, or it doesn't.

If your $sendall is getting wider than the screen it is probably going to be difficult for others to debug and understand. You should not assume that others will understand your $sendall statement, so be sure to clearly comment it.

$sendall is a group method which sends a message to all the items in a group. When I first read about $sendall in the Omnis Studio documentation I only considered it for window objects and report objects. It never occured to me that $sendall could be used for lists. A list is structured as a group of rows, so using $sendall on a list will send a message to each row of the list.

So the first thing you need to visualize is that a list variable has a group of rows, in the same way that a window has a group of field objects.

Note

$sendall is not faster than a For loop. The List.$sendall processes each line of the list, just like a For loop. If you are only processing the selected lines of a large list, using $first & $next with the selected line arguments will be slightly faster than using $sendall. If you are issuing $sendall more than once to the same list you should consider using a single For loop.

In this section we will start with a simple List.$sendall example, and then gradually get more and more complex, explaining each example as we go. By the end of this section you will be able to join the ranks of List.$sendall($ref.guru)!

List.$sendall Syntax

Do List.$sendall($ref.ColName.$assign(Value),[Criteria]) Returns Count

Splitting the $sendall notation:

Think of List.$sendall as a single line loop.

List.$sendall is the For & End For in a single line.

For List.$line from 1 to List.$linecount step 1

End For

What you put between the parenthesis before the comma is the middle part inside the loop. ($ref.C1.$assign(List.$line))

For List.$line from 1 to List.$linecount step 1
  Calculate List.C1 as List.$line
End For

What you put in the brackets after the comma is the If & End if part inside the loop. ( ,$ref.0.$selected)

For List.$line from 1 to List.$linecount step 1
  If List.0.$selected
    Calculate List.C1 as List.$line
  End If
End For

You can get as complex as you like with the optional [Criteria]. Criteria accepts | (or) and &

Note

List.$sendall changes the current line in the list. It operates like a loop, changing the current line to the line being processed as it steps through the list. The last line in a list will always be the current line after you issue a List.$sendall.

List.$sendall Examples

The following examples give you some ideas of things you can do with List.$sendall.

; Increment each value in a column by 1.
Do List.$sendall($ref.ColName.$assign(List.ColName+1))
; or
Do List.$sendall($ref.ColName.$assign($ref+1))

Note

Why were we able to replace List.ColName with $ref in the second part of the above example? With Omnis notation, $ref is an argument which points to the notation which preceeds $ref in the string. In the above example the first $ref points to List which preceeds it. The second $ref point to $ref.Value which preceeds it.

; Add the value of each "List.ColName" to "Total" for the selected lines.
Do List.$sendall(Total.$assign(Total+List.ColName),List.0.$selected)
; or
Do List.$sendall(Total.$assign($ref+List.ColName),List.0.$selected)

; The $ref in the second example points to the variable "Total" which preceeds it.
; Therefore we can use $ref in place of the second "Total" in the sendall.

Note

For list totals use the $total or $totc methods. The above is just a demonstration of List.$sendall.

; Pad each "List.ColName" with preceeding zeros using the jst() function.
Do List.$sendall($ref.ColName.$assign(jst($ref,'-3P0')))

; Calculate the subtotal for every line in the list.
Do List.$sendall($ref.Subtotal.$assign(List.Qty*List.CostPer))

; Set a column value to the line number.
Do List.$sendall($ref.ColName.$assign(List.$line))