[X++] Get translated product name for language

When having a look at the method title on table InventTable it shows a way to get the translated product name for a specific langauge by code.

\Data Dictionary\Tables\InventTable\Methods\title

/// <summary>
///    Retrieves the ID and a product name of the current product per company and combines it into a title.
/// </summary>
/// <returns>
///    The title of the current product per company.
/// </returns>
/// <remarks>
///    The method is used as a title in product per company list page and details forms.
public display EcoResProductTitle title()
    EcoResProductName   productName;

    productName = EcoResProductTranslation::getNameOrDefaultName(this.Product, CompanyInfo::languageId());
    if (productName)
        return strFmt('%1 : %2', this.ItemId, productName);

    return this.ItemId;

So to adapt the code we can call EcoResProductTranslation::getNameOrDefaultName with the RecId of the needed product and the languageId for the language we want to have the name in:

    EcoResProductName   productName;
    InventTable         inventTable = InventTable::find('MyItemId');
    LanguageId          languageId  = 'en-us'; // CompanyInfo::languageId()

    productName = EcoResProductTranslation::getNameOrDefaultName(inventTable.Product, languageId);
    if (productName)
        info( productName );
// ...


Software Engineer / Application Developer

Subscribe to robsCode

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!