Anvaigo Mobile App / Best Practices / Lookups on Card Pages

Lookups on Card Pages

A lookup on a card page gives you the ability to simply select a value from a list instead of typing it in. Typical scenarios from Dynamics are code fields that have a very short name only. It requires a description to understand its value. Furthermore, lookups might speed up the input process significantly.

General Concept

Contrary to Dynamics, Anvaigo Mobile App does not have an automatism to activate a lookup on a field. This allows a much more flexible configuration. It is put together of three basic components: Button on a card page to open the list view, Anvaigo Page of type list to show the lookup values and an Anvaigo Script to save the selected value in the record.

Anvaigo Mobile App provides an example on Anvaigo Page ASLS_CUSTOMER with a lookup to salespersons using Anvaigo Page Anvaigo Page ASLS_SALESPERSON_LU.

1. Create new Anvaigo Page of type list

The first step is to create a new list page that shows your lookup screen (see here). This Anvaigo Page can be used for lookups only, but you can add menu entries for further navigation if required. Example Anvaigo Page is ASLS_SALESPERSON_LU.

2. Open lookup Anvaigo Page via button

In the second step, add a button on your card page using an Anvaigo Script code to open your lookup Anvaigo Page. Add a Button to your Anvaigo Page (see here). Because you might already have a global table relation between the two records of source and lookup Anvaigo Page (see here), the lookup Anvaigo Page must be opened via Anvaigo Script without any filters. Add a new Action Code and assign it to your button (see here). The following Anvaigo Script code opens your Anvaigo Page without any filters:

local Salesperson = Record('Salesperson/Purchaser');
PAGE_OPEN('ASLS_SALESPERSON_LU', Salesperson,Rec);
Example Anvaigo Script code to open an Anvaigo Page without any filters.

Example see Anvaigo Page ASLS_CUSTOMER , Action Code ASLS_OPN:PAYTERMS_LU.

3. Action Code on your lookup Anvaigo Page

Last step is to add a new Action Code that is run on Mobile Shortpress event (see Short Press Action). It saves the selected value to your source record srcRec in the card and closes the lookup Anvaigo Page.

if (srcRec) then
[[Lookup Page can be used for multiple sources]]
if (srcRec:GETTABLENAME() == 'Customer') then
[[Write value back to customer table and close Anvaigo Page]]
srcRec:SETVALUE('Salesperson Code', Rec:GETVALUE('Code'));
srcRec:MODIFY(false);
PAGE('CLOSE');
else
[[Error message if source is not defined yet]]
MESSAGE('Cannot perform action because src table is '
.. srcRec:GETTABLENAME());
end;
end;
Example Anvaigo Script code to write back a selected value into the source table.

A lookup Anvaigo Page can be used multiple times for different source tables. In this example, you can use the Anvaigo Page also for a lookup on the sales header or contact. Simply add new source tables the last Anvaigo Script. In srcRec you know from where the Anvaigo Page was opened.

In some scenarios a lookup Anvaigo Page is opened from different fields but from same table. Then, the last write-back Anvaigo Script does not know where to write the data to. It requires additional code.
Option 1: use multiple lookup Anvaigo Pages.
Option 2: Remember the source field in table ACF Lookup Helper like a global variable and use it when writing back into the source table.
Example:  Sell-to Customer No. and Bill-to Customer No. lookup in table Sales Header.