Association

WorkWithPlus provides the possibility to associate at runtime records that belong to certain transaction, to another transaction when it exists a N-to-N relation between them (with an association transaction).

In order to describe this feature, we will suppose that our application must handle multiple companies, and in each one we have to work with different currencies. This functionality allows application user to set which currencies will be associated to which companies in a simply and efficient way, like we explain below.

We will have 'Company' transaction which will represent the existing companies; 'Currency' transaction will represent all the existing currencies that can be needed for some Company record; and in order to associate which currencies are associated to a company, we have 'CurrencyCompany' transaction. This transaction relates 'Company' with 'Currency' in an n to n relation.

Company transaction

The Company transaction's Structure tab lists its attributes: CompanyId (Id, key, description "Company Id"), CompanyName (VarChar(40), "Company Name"), and CompanySlogan (VarChar(40), "Company Slogan"), none nullable.

Currency Transaction

The Currency transaction structure editor lists its attributes in a table with Name, Type, Description, Formula, and Nullable columns: CurrencyId (Character(3), key), CurrencyDescription (VarChar(40)), and CurrencyNum (Numeric(4.0)). Tabs above the grid include Structure, Web Form, Win Form, Rules, Events, Variables, Help, Documentation, and Patterns.

N-to-N relation transaction (CompanyCurrency)

The CompanyCurrency transaction's Structure tab lists attributes CompanyId (Id), CurrencyId (Character(3)), CurrencyDescription, and CompanyName; a red box highlights the two key attributes CompanyId/CurrencyId on the left and the Business Component property set to True in the Properties panel on the right, identifying CompanyCurrency as the relation transaction between Company and Currency.

This transaction contains as a primary key the PKs of both transactions (Company and Currency). It is necessary to set this transaction as Business Component because pattern will need to insert or delete records to this transaction when associating or disassociating a company to a certain currency.

So, now we insert the association node, like we can visualize below:

In the Company transaction's Patterns tab with Work With Plus applied, the pattern object tree toolbar's add-object dropdown is open, listing ExtraSelection, ExtraView, Prompt, PromptMultiple, Association, and AssociationSelection; the "Association" option is highlighted with a red box.

After we click on 'Add Association Web Panel', the following window will appear:

An "Add Association" dialog over the Company transaction pattern editor shows an empty combo box labeled "Select Relation Transaction for 'Company'" with Create and Cancel buttons; a red annotation explains this combo lists transactions that relate Company to another transaction in an n-to-n relation, such as Currency, and instructs selecting the transaction to associate then pressing Select.

We select CompanyCurrency:

The "Add Association" dialog shows the combo box "Select Relation Transaction for 'Company'" with "CompanyCurrency (Related Table: Currency)" selected, alongside Create and Cancel buttons.

Finally we press Select, and an Association Node will be inserted in Company instance, containing all the children, its properties and order from Instance Template, like we can appreciate below:

The Company transaction's Patterns tab shows the newly created Association (CompanyCurrency) node fully expanded and enclosed in a red box, containing Relation Transaction, TableMain with TableTitle (Associated to Company, CompanyName), Error viewer, TableFullContent with TableNotAssociated/Association Buttons/TableAssociated (Registros No Asociados / Registros Asociados), and an Action Group with Confirm/Cancel.

If we execute Preview action over Association node, we will visualize how Association web form will look like:

The "Associated to Company :: 3M" web page shows a Not Associated Records list of currencies and an Associated Records list containing Afghanistan Afghanis - AFN, Austria Schillings - ATS, Bahamas Dollars - BSD, and Barbados Dollars - BBD, with four transfer buttons between the lists and Confirm/Cancel buttons below.

Then, in order to test this functionality we insert a User Action in Selection object's Grid, which will invoke the Association Web Panel as follows:

The Company Selection pattern tree shows a User Action (Association) node highlighted under the Grid's Action Group; the Properties panel on the right, enclosed in a red box, shows Caption "Associate Currencies", GXObject AssociationCompanyCompanyCurrency, Confirm True with confirmation Title "Associate Currencies", Type YesNo, and Visible True at all breakpoints.

We save the object and watch the results at runtime. The WWCompanies has the action to call to Association Web panel:

The Companies grid web page lists companies (3M, Disco, DVelop, GeneXus, IBM, Salto Grande, Summum, TCS, Tienda Inglesa) with Id, Name, Description, and Logo columns. On the Disco row, the "Select an action" dropdown is open showing options "Associate Currencies (Selection)" and "Associate Currencies", with the latter highlighted.

After we click on this option for Dvelop company, and Association Web Panel is displayed. As it is the first time we access to it, this company does not have any currencies associated.

The "Associated to Company :: DVelop" web page shows the Not Associated Records list of currencies with "Afghanistan Afghanis - AFN" selected, an empty Associated Records list, four transfer buttons between them, and Confirm/Cancel buttons below.

We could associate to Dvelop all the currencies that exist in the system, by clicking in the first button:

The "Associated to Company :: DVelop" web page shows the Not Associated Records currency list with "Afghanistan Afghanis - AFN" selected and an empty Associated Records list; the top transfer button (move all records right) is highlighted with a red box.

And we can appreciate that all the currencies are associated to Dvelop. We make the opposite action, by clicking on the last button so to disassociate all the currencies from Dvelop company. 

The "Associated to Company :: DVelop" web page shows an empty Not Associated Records list and the full currency list moved into Associated Records; the bottom transfer button (move all records back left) is highlighted with a red box.

We select the currency 'Dollars' and press the second button, in order to associate this currency to Dvelop (this action also could be accomplished by doing double-click into the currency we want to associate/disassociate).

The "Associated to Company :: DVelop" web page shows the Not Associated Records list with "America (United States Dollars - US$" selected and an empty Associated Records list; the second transfer button (move single record right) is highlighted with a red box.

We repeat the procedure above for 'Chile Pesos', 'Euro' and 'Mexico Pesos' and then press 'Confirm'.

The "Associated to Company :: DVelop" web page shows the Not Associated Records currency list on the left and an Associated Records list containing America (US$), Chile Pesos - CLP, Euro - EUR, and Mexico Pesos - MXN on the right; the Confirm button at the bottom left is highlighted with a red box.

The application will return to CompaniesWW. Then we select the option to ViewCompany 'DVelop' in order to visualize the results:

The "Company :: DVelop" view page shows tabs General, Auditing, Currencies, and Persons, with the Currencies tab active. It displays a search bar filtering by Currency Description and a grid with Currency Id and Currency Description columns listing BRL (Brazil Reais), EUR (Euro), FRF (France Francs*), and ITL (Italy Lire*).

And we can guarantee that the currencies were correctly associated to 'DVelop'.

If you want to read information about Association Node properties, follow this link: Association Node