Call (Imagine function): Difference between revisions
Document stringLists and dollarLists arguments |
|||
| Line 20: | Line 20: | ||
<tr><th><var>recordMap</var></th> | <tr><th><var>recordMap</var></th> | ||
<td>A <var>Boolean</var> value that indicates whether a map of (thread-specific) <var class="product">Model 204</var> record numbers to <var class="product">Imagine</var> file and recordId should be sent to <var class="product">Imagine</var>. This can be useful if one is passing <var class="product">Model 204</var> record numbers to the <var class="product">Imagine</var> application. The default value of this argument is <var>false</var>.</td></tr> | <td>A <var>Boolean</var> value that indicates whether a map of (thread-specific) <var class="product">Model 204</var> record numbers to <var class="product">Imagine</var> file and recordId should be sent to <var class="product">Imagine</var>. This can be useful if one is passing <var class="product">Model 204</var> record numbers to the <var class="product">Imagine</var> application. The default value of this argument is <var>false</var>.</td></tr> | ||
<tr><th><var>stringLists</var></th> | |||
<td>A <var>StringListList</var> (a <var>NamedArraylist</var> of <var>Object Stringlist</var>) whose entries are sent to the <var class="product">Imagine</var> function as named <var>Stringlist</var>s. Each <var>Stringlist</var> in the collection is sent together with its <var>NamedArraylist</var> item name, so the called code can refer to each list by name. The default is null (no <var>Stringlist</var>s sent). | |||
<p> | |||
If a <var>Stringlist</var> is bound to a server image via the <code>NAMESAVE</code> image attribute, each item is validated against the image's field-data length, and the image itself is sent so that <var class="product">Imagine</var> can interpret the fields by name. Unbound <var>Stringlist</var>s are sent with no image, and each item is sent with its actual length. | |||
</p><p> | |||
After the call, <var class="product">Imagine</var> can return updated versions of any subset of the supplied <var>Stringlist</var>s, identified by their position (1-based ordinal) in the <var>StringListList</var>. The corresponding target <var>Stringlist</var> is emptied and refilled with the returned items, subject to the same image-binding validation that was applied on the send: items in an image-bound <var>Stringlist</var> must match the image's field-data length. | |||
</p><p> | |||
This argument requires <var class="product">Imagine Transparency</var> broker protocol version 4 or later. The list-name feature requires broker protocol version 8 or later; with an older broker, the lists are still sent in order but without their names.</td></tr> | |||
<tr><th><var>dollarLists</var></th> | |||
<td>A <var>DollarListList</var> (a <var>NamedArraylist</var> of <var>Fixed</var>) whose entries are $list identifiers sent to the <var class="product">Imagine</var> function as named $lists. Each $list in the collection is sent together with its <var>NamedArraylist</var> item name, so the called code can refer to each $list by name. The default is null (no $lists sent). | |||
<p> | |||
If a $list is bound to a server image via the <code>NAMESAVE</code> image attribute, each item is validated against the image's field-data length, and the image itself is sent so that <var class="product">Imagine</var> can interpret the fields by name. Unbound $lists are sent with no image, and each item is sent with its actual length. | |||
</p><p> | |||
After the call, <var class="product">Imagine</var> can return updated versions of any subset of the supplied $lists, identified by their position (1-based ordinal) in the <var>DollarListList</var>. The corresponding target $list is emptied and refilled with the returned items, subject to the same image-binding validation that was applied on the send: items in an image-bound $list must match the image's field-data length. | |||
</p><p> | |||
This argument requires <var class="product">Imagine Transparency</var> broker protocol version 4 or later. The list-name feature requires broker protocol version 8 or later; with an older broker, the $lists are still sent in order but without their names.</td></tr> | |||
</table> | </table> | ||
| Line 25: | Line 41: | ||
In <var class="product">Imagine</var>, a transaction includes both retrieval requests and updating requests. | In <var class="product">Imagine</var>, a transaction includes both retrieval requests and updating requests. | ||
<p> | <p> | ||
Because <var class="product">Imagine Transparency</var> files and transactions are automatically kept in synch with the corresponding files in <var class="product">Model 204</var> any updates in the <var class="product">Model 204</var> transaction are visible in the <var class="product">Imagine</var> transaction and vice versa==Examples== | Because <var class="product">Imagine Transparency</var> files and transactions are automatically kept in synch with the corresponding files in <var class="product">Model 204</var> any updates in the <var class="product">Model 204</var> transaction are visible in the <var class="product">Imagine</var> transaction and vice versa. | ||
</p><p> | |||
The <var>stringLists</var> and <var>dollarLists</var> arguments are designed for bulk transfer of structured data to and from the <var class="product">Imagine</var> function in a single call. <var>Stringlist</var>s and $lists carry essentially the same payload — a sequence of variable-length byte strings — but appear in <var class="product">User Language</var> code as different types, so the two arguments let the caller use whichever form is more natural in the surrounding code. Mixing the two is allowed: both can be supplied in the same <var>Call</var>. | |||
</p><p> | |||
The pairing of a list with an image binding lets <var class="product">Imagine</var> reach individual fields by name on its side. To use this, declare the bound image with the <code>NAMESAVE</code> attribute and bind the <var>Stringlist</var> (with <var>BindImage</var>) or $list (with <code>$LstImg_Bind</code>) before adding items. Items in an image-bound list must be exactly the image's field-data length; otherwise <var>Call</var> cancels the request with an "Item length mismatch" error. Lists with no image binding are sent as raw variable-length strings. | |||
</p><p> | |||
On return, <var class="product">Imagine</var> may replace the contents of any of the supplied lists. Each returned list is identified by its position in the original <var>StringListList</var> or <var>DollarListList</var>; the target list is emptied first and then refilled with the items returned by the broker. The same image-binding rule applies to the returned items. | |||
</p> | |||
==Examples== | |||
The following example sends a single <var>Stringlist</var> of order rows to an <var class="product">Imagine</var> function and prints whatever items the broker writes back into that list: | |||
<p class="code">%orders is object Stringlist | |||
%orderLists is object NamedArraylist of Object Stringlist | |||
%result is string len 256 | |||
%orders = New | |||
%orders:Add('order=1001 qty=2') | |||
%orders:Add('order=1002 qty=5') | |||
%orderLists = New | |||
%orderLists('orders') = %orders | |||
%result = %(Imagine):Call('processOrders', stringLists=%orderLists) | |||
For %i From 1 To %orders:Count | |||
Print %orders(%i) | |||
End For | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:Imagine:Call footer}} | {{Template:Imagine:Call footer}} | ||
Latest revision as of 13:48, 19 June 2026
Run Imagine code on the Transparency Broker (Imagine class)
[Introduced in Model 204 8.0 βeta]
This method calls code running in the Imagine Transparency broker for the current transaction.
Syntax
[%string =] %(Imagine):Call( name, [payload= string], [globals= boolean], - [globalImages= boolean], [recordMap= boolean], - [stringLists= stringListList], - [dollarLists= dollarListList], - [apsySuffix= string]) Throws BrokerLost, BrokerCallError
Syntax terms
| %string | The value returned by the called Imagine function. This could be anything though JSON would be the most convenient format for passing data from Imagine to Model 204. |
|---|---|
| %(Imagine) | The class name in parentheses denotes a shared method. Call can also be invoked via a Imagine object variable, which may be Null. |
| name | A string that contains the name of the function to be called in the Imagine broker. The semantics of this value is under the control of the Imagine broker. |
| payload | A string that contains data passed to the Imagine function. This could be anything though JSON would be the most convenient format for passing data to the Imagine function. Thwe default value for this is an empty string. |
| globals | A Boolean value that indicates whether global strings ($setg/$getg) should be sent to Imagine. The default value of this argument is false. |
| globalImages | A Boolean value that indicates whether global images should be sent to Imagine. The default value of this argument is false. |
| recordMap | A Boolean value that indicates whether a map of (thread-specific) Model 204 record numbers to Imagine file and recordId should be sent to Imagine. This can be useful if one is passing Model 204 record numbers to the Imagine application. The default value of this argument is false. |
| stringLists | A StringListList (a NamedArraylist of Object Stringlist) whose entries are sent to the Imagine function as named Stringlists. Each Stringlist in the collection is sent together with its NamedArraylist item name, so the called code can refer to each list by name. The default is null (no Stringlists sent).
If a Stringlist is bound to a server image via the
After the call, Imagine can return updated versions of any subset of the supplied Stringlists, identified by their position (1-based ordinal) in the StringListList. The corresponding target Stringlist is emptied and refilled with the returned items, subject to the same image-binding validation that was applied on the send: items in an image-bound Stringlist must match the image's field-data length. This argument requires Imagine Transparency broker protocol version 4 or later. The list-name feature requires broker protocol version 8 or later; with an older broker, the lists are still sent in order but without their names. |
| dollarLists | A DollarListList (a NamedArraylist of Fixed) whose entries are $list identifiers sent to the Imagine function as named $lists. Each $list in the collection is sent together with its NamedArraylist item name, so the called code can refer to each $list by name. The default is null (no $lists sent).
If a $list is bound to a server image via the
After the call, Imagine can return updated versions of any subset of the supplied $lists, identified by their position (1-based ordinal) in the DollarListList. The corresponding target $list is emptied and refilled with the returned items, subject to the same image-binding validation that was applied on the send: items in an image-bound $list must match the image's field-data length. This argument requires Imagine Transparency broker protocol version 4 or later. The list-name feature requires broker protocol version 8 or later; with an older broker, the $lists are still sent in order but without their names. |
Usage notes
In Imagine, a transaction includes both retrieval requests and updating requests.
Because Imagine Transparency files and transactions are automatically kept in synch with the corresponding files in Model 204 any updates in the Model 204 transaction are visible in the Imagine transaction and vice versa.
The stringLists and dollarLists arguments are designed for bulk transfer of structured data to and from the Imagine function in a single call. Stringlists and $lists carry essentially the same payload — a sequence of variable-length byte strings — but appear in User Language code as different types, so the two arguments let the caller use whichever form is more natural in the surrounding code. Mixing the two is allowed: both can be supplied in the same Call.
The pairing of a list with an image binding lets Imagine reach individual fields by name on its side. To use this, declare the bound image with the NAMESAVE attribute and bind the Stringlist (with BindImage) or $list (with $LstImg_Bind) before adding items. Items in an image-bound list must be exactly the image's field-data length; otherwise Call cancels the request with an "Item length mismatch" error. Lists with no image binding are sent as raw variable-length strings.
On return, Imagine may replace the contents of any of the supplied lists. Each returned list is identified by its position in the original StringListList or DollarListList; the target list is emptied first and then refilled with the items returned by the broker. The same image-binding rule applies to the returned items.
Examples
The following example sends a single Stringlist of order rows to an Imagine function and prints whatever items the broker writes back into that list:
%orders is object Stringlist %orderLists is object NamedArraylist of Object Stringlist %result is string len 256 %orders = New %orders:Add('order=1001 qty=2') %orders:Add('order=1002 qty=5') %orderLists = New %orderLists('orders') = %orders %result = %(Imagine):Call('processOrders', stringLists=%orderLists) For %i From 1 To %orders:Count Print %orders(%i) End For