Referencing Uniface V7.2.05 Fields in Javascript

The format for generating field names in HTML appears to have changed in 7.2.05 in the HTML source (addition of ".1." to field name values). This causes problems when accessing fields from Javascript.

Why does this behavior occur in UV7.2.05?
In Uniface V7.2.04, multiple occurrence behavior was handled in HTML by the <X-ITERATE> tag, which has been replace in Uniface V7.2.05 by the <X-OCCURRENCE> tag. Since the <X-OCCURRENCE> tag is generated during HTS file creation for all entities, whether they are multi-occurrence entities or single occurrence entities, the field names are furnished with an additional occurrence number (FIELD.ENTITY.MODEL.1.).

While in Uniface V7.2.04, a single occurrence entity field name could be used to reference the filed value, the addition of the occurrence number (.1.) invalidates that Javascript. For example:

UV7.2.04 - parent.basefrm.document.forms[0].elements["FIELD_NAME.ENTITY.MODEL"].value="FIELD_VALUE"
Needed to be modified to work in
UV7.2.05 - parent.basefrm.document.forms[0].elements["FIELD_NAME.ENTITY.MODEL.1."].value="FIELD_VALUE"

Occurrence handling in Uniface V7.2.05
A UNIFACE Web form is a stateless form that is only active for the duration of a user request. When an HTML form is created, UNIFACE handles occurrences by adding additional information about each occurrence. The beginning of each occurrence is marked with information about the database state of that occurrence. Two hidden fields are added to each occurrence in the HTML source just before the first field. The names of these fields start with a hash character (#). The value of the first field is the partially encoded primary key, and the second field is the CRC checksum.

If the occurrence was already stored in the database, the invisible field added just before the first entity field starting with a hash character (#) contains the value of the partially encoded primary key of this occurrence. This is done so that UNIFACE can restore the database context in the next request. For example:

A non-database entity is preceded by a percent sign (%). In this case, no attempt is made to reconnect to the database

The CRC checksum mechanism is added to provide a means of checking whether database occurrences have been modified after a browser requested the occurrence and before the browser returned the data to the server. It is a 32-bit number calculated from the values of all the fields in a database occurrence. Any change to the occurrence produces a different CRC checksum value. This value is stored in a hidden field of each database occurrence loaded into a Web page. When the browser returns the page, CRC values are calculated for each database occurrence the browser attempts to overwrite during processing of the webget statement. Occurrences whose CRC checksum no longer matches the database produce an error ($error 2012) and fire the entity-level On Error trigger.

Field name handling in Uniface V7.2.05 and implications with using javascript
HTML 4.0 does not make provision for occurrences. UNIFACE handles this by including an occurrence index number in the field name generated for each field. Each field name is the full description of FIELD.ENTITY.MODEL with the addition of an occurrence number (.1.). All fields of the same occurrence have the same index number

Nested entity field names are identified with and additional inner level occurrence number. For example:
<INPUT TYPE="HIDDEN" NAME="%.OUTER_ENTITY.MODEL.1." VALUE="">
<INPUT TYPE="HIDDEN" NAME="%.INNER_ENTITY.MODEL.1-1." VALUE="">
<INPUT TYPE="HIDDEN" NAME="%.INNER_INNER_ENTITY.MODEL.1-1-1." VALUE="">
<INPUT TYPE="HIDDEN" NAME="%.INNER_ENTITY.MODEL.1-2." VALUE="">

Uniface Library Documentation Summary on Working with HTML and Javascript
Uniface Library:

How to -> Construct components -> Working with HTML skeletons -> Working with JavaScript

To address another field belonging to the same occurrence as the currently active field, do the following (an occurrence level event is required in order to utilize this method to address fields in the same occurrence in a Web page with JavaScript):

  1. Assign the field name to a variable, substituting the target field name for the current field name, using the following syntax:

    var=Object.name.replace(/Fld1.Ent.Model/gi, "Fld2.Ent.Model");

    where:
    var-is a variable
    Object-is the object that activated the JavaScript, such as a CheckBoxObject
    Fld1-is the field represented by Object
    Fld2-is the target field
    Ent-is the entity of which Fld1 and Fld2 are members
    Model-is the application model of Ent


  2. Refer to the target field through an element array, indexed on name

    Example:
    The following JavaScript comes from an HTML skeleton for an order form. The user clicks a check box (CHECK.ARTICLE) to order a particular item, and then enters the number of items required in a field named QUANTITY.ARTICLE. If a user checks CHECK.ARTICLE, the QUANTITY.ARTICLE field should be automatically assigned a value of 1. JavaScript can achieve this, but the following issues must be handled:

    JavaScript cannot directly address field names in Web pages generated from UNIFACE Server Pages because UNIFACE and JavaScript interpret periods in field names differently. The following example places the required field name in a variable and uses this name as an array index value to locate the field in the document. HTML 4.0 does not support the concept of occurrences, so JavaScript cannot automatically recognize which fields belong to the same occurrence. All the fields of an occurrence have the same index number. In the following example, the full field name is placed in a variable and then the field index number is re-used in a new field name.

    <html>
    <head>
    <script language="JavaScript">
    function SetQuantityField(CheckBoxObject)
    {
    // The name of the CheckBoxObject contains the field
    // name "CHECK.ARTICLE.ORDSYS" extended with an index number.
    // Replace this field name with QUANTITY.ARTICLE.ORDSYS
    // giving a field name of the QUANTITY with the same
    // index number as the check box field.

    QuantityField=CheckBoxObject.name.replace(/CHECK.ARTICLE. ORDSYS/gi, "QUANTITY.ARTICLE.ORDSYS");

    // Index the elements with the QUANTITY field name
    // in the Order form and set the field value to 1
    // if the check box is checked.
    // If the check box is not checked, clear QUANTITY.

    if ( CheckBoxObject.checked == "1" )
    document.theOrderForm.elements[QuantityField].value = "1";
    else
    document.theOrderForm.elements[QuantityField].value = "";
    }

    </script>
    </head>
    <body>
    <form method="post" action="" name="theOrderForm">
    <x-iterate name="ARTICLE.ORDSYS" AtLeastOne start="first">
    <x-subst type="checkbox" name="CHECK.ARTICLE.ORDSYS" onClick="SetQuantityField(this)">
    <input type="checkbox" name="CHECK.ARTICLE.ORDSYS" value="">
    </x-subst>
    <x-subst type="text" name="QUANTITY.ARTICLE.ORDSYS" size="3"> <input type="text" name="QUANTITY.ARTICLE.ORDSYS" value="">
    </x-subst>
    </x-iterate>
    </form>
    </body>
    </html>

    Recommendations
    We have noticed some unpredictable behavior (such as indexes that are .1 instead of the expected .1.). We are currently still in the process of establishing a more formal way for dealing with occurrence handling.

    For now, when the needed functionality can be triggered by an occurrence level event, use the example documented in the Uniface library and described above by indirectly referencing the javascript name.

    If the field name is unique to the HTML source (single occurrence entity field - "FIELD_NAME.ENTITY.MODEL"), you can loop through the object names searching for a specified name in the page using the javascript find method. This will only work if there is one occurrence of that field.

    Otherwise, the field names will have to be hardcoded for the time being.