How to set a default association?

0
Entity CurrencyCodes is more or less a list of constants (can only be edited by administration/maintenance personnel.  It has entries such a USD, CAD, EURO etc.  When I create a new PurchaseRequisition I want it to always default to the USD association with CurrencyCodes.  How do I do this? Thank you!!   x Regards, Ted.
asked
2 answers
4

Using a AfterCreate Event on PurchaseRequisition.

You’re right that there is no setting on associations for selecting a default. The reason is that none of the associations (pointing to a value) is certain to exist. Take this into account in the ACr_PurchaseRequisition_SetCurrency, so not to run into an error.

answered
1

One addition to Tim's solution;

Retrieving the default currency by constraining on a specific value can result in errors when value doesn't exists.

So instead of constraining on autonumberID or Code I would introduce a boolean to mark an object/record as default. + some logic to enforce that only one can be true. And to make it as fancy as possible; after retrieve, check if found; if found, use it. If not retrieve just the first one of the database and use that one. The last won't result in the default one, but at least a currency is set.

 

answered