So What Exactly Does a Translation Function Spec Do?

Let's look at the Translation Function Spec used within the Food Bank customization. Specifically, let's look at what happens when we modify the user-defined function (UDF) within the spec by changing the value returned. The USF below accepts the ID of a food item, uses a Transact-SQL SELECT statement to translate the GUID to the name of the food item, and then returns the name.

<TranslationFunctionSpec
    xmlns="bb_appfx_translationfunction"
    xmlns:common="bb_appfx_commontypes"
    ID="9EDCED28-35EF-481f-9BB9-CFB110A92881"
    Name="Food Item Translation Function"
    Description="Get the food item's name."
    Author="Technical Training"
    RecordType="Food Item"
    >

    <SQLTranslationFunction FNName="USR_UFN_TRANSLATIONFUNCTION_FOODITEM">
        <common:CreateFunctionSQL>
            <![CDATA[
create function dbo.USR_UFN_TRANSLATIONFUNCTION_FOODITEM(@ID uniqueidentifier) 
returns nvarchar(100) 
as
begin
    declare @s nvarchar(100);
    select 
        @s = NAME 
    from 
        dbo.USR_FOODITEM 
    where ID = @ID;
    return @s;
end    
            ] ]>
        </common:CreateFunctionSQL>
    </SQLTranslationFunction>
</TranslationFunctionSpec>

The ID of the TranslationFunctionSpec is referenced within the Food Item search list:

<SearchListSpec 
    xmlns="bb_appfx_searchlist"
    xmlns:common="bb_appfx_commontypes"
    ID="2C247ADD-E19E-407f-B6C3-8F3BC5216CCD"
    Name="Food Item Search"
    Description="Search list for food items."
    Author="Technical Training"
    RecordType="Food Item"
    TranslationFunctionID="9EDCED28-35EF-481f-9BB9-CFB110A92881"
    >

    <!-- describe the SP used to fetch the results from the given filters. Note that the @MAXROWS parameter is required, and should be 
    used to limit the number of rows returned to a reasonable number. -->
    <SPSearchList SPName="USR_USP_SEARCHLIST_FOODITEM">
        <common:CreateProcedureSQL>
            <![CDATA[
create procedure dbo.USR_USP_SEARCHLIST_FOODITEM
(
    @NAME nvarchar(100) = null,
    @MAXROWS smallint = 500
)
as

Whenever the Food Item search list is utilized within the form fields of a data form such as the Food Bank Transaction Detail Add Form (green highlight)...

<c:FormMetaData FixedDialog="true">
        <c:FormFields>
                  <c:FormField FieldID="FOODITEMID" DataType="Guid" Required="true" Caption="Food Item">
                        <c:SearchList SearchListID="2C247ADD-E19E-407f-B6C3-8F3BC5216CCD" EnableQuickFind="true"/>
                  </c:FormField>    
            <c:FormField FieldID="FOODITEMAMOUNT" DataType="Money" Caption="Food Item Amount" />
            <c:FormField FieldID="QUANTITY" DataType="SmallInt" Caption="Quantity" DefaultValueText="1" />
        </c:FormFields>

....the Infinity platform renders the search list on the user interface as such:

When the icon is clicked in the Food Item form field (above), the Food Item search list appears (below). We can search for a food item and then click the Select button to provide the selected food item back to the data form. Behind the scenes, the Food Item ID (GUID) is provided to the data form. However, the translation function spec takes the GUID and translates it into a human readable form, like the food item name.

If we modify the translation function spec to return a different translation (orange highlight below), we can see the results when we search for a food item again within the data form. Here we change the value returned within the translation function spec from the food item name to the food item name plus " … tasty!"

<TranslationFunctionSpec
    xmlns="bb_appfx_translationfunction"
    xmlns:common="bb_appfx_commontypes"
    ID="9EDCED28-35EF-481f-9BB9-CFB110A92881"
    Name="Food Item Translation Function"
    Description="Get the food item's name."
    Author="Technical Training"
    RecordType="Food Item"
    >

    <SQLTranslationFunction FNName="USR_UFN_TRANSLATIONFUNCTION_FOODITEM">
        <common:CreateFunctionSQL>
            <![CDATA[
create function dbo.USR_UFN_TRANSLATIONFUNCTION_FOODITEM(@ID uniqueidentifier) 
returns nvarchar(100) 
as
begin
    declare @s nvarchar(100);
    select 
        @s = NAME + ' ... tasty!'
    from 
        dbo.USR_FOODITEM 
    where ID = @ID;
    return @s;
end    
            ]]>
        </common:CreateFunctionSQL>
    </SQLTranslationFunction>
</TranslationFunctionSpec>

We load the modified spec into our Infinity database and call upon the search form again within the data form. This time when the Food Item is searched, a different translation of the food item is provided.