mergeFirstRecordFromInfoBus method



Initiates a merge operation.

Syntax

success  = WordProcessor.mergeFirstRecordFromInfoBus(itemName)

Applies to

WordProcessor object.

Parameters

itemName
string. The name of an InfoBus data item holding data to be inserted into one or more fields in a WordProcessor document.

Return value

boolean. Returns true if the initial merge operation was completed successfully, and false otherwise.

Usage

To perform a merge operation (in which data from an external file is inserted into into predefined fields in a document), you need to do the following:
  1. Create a data table in a format that the InfoBus can read and broadcast to the WP applet as a data item. This InfoBus item must be a two-dimensional array in the following format:
    Fieldname1      Fieldname2      Fieldname3      ...     Fieldnamen
    field1          field2          field3  ...             fieldn
    field1          field2          field3  ...             fieldn
    
    The first row in the array supplies the names of the fields; subsequent rows represent the field data to be merged. For example:
    "First"		"Last"	"EMailAddr"			"Subject"
    "Cynthia"       "Smith" "csmith@somewhere.com"          "Product questions"
    
  2. Create and save a WP template using the WP template builder.

  3. Using a text editor, insert <VAR> tags for the fields that you want to populate with the data item data. For example:
    <b><VAR NAME="First">First</VAR> <VAR NAME="Last">Last</VAR></B><P>
    <b><VAR NAME="EMailAddr">e-mail Address</VAR></b><P>
    Subject: <B><VAR NAME="Subject">Subject</VAR></B><P>
    <P>
    Dear <B><VAR NAME="First">First</VAR>:</B>
    
    The bold text shows the opening <VAR> tag of each merge field. In the current example, fields named "First", "Last", "EMailAddr" and "Subject" have been specified. Note that "First" is referenced twice in the template. In the merge operation, all template text between the close of the <VAR> tag and the start of the </VAR> tag will be replaced by the supplied field data. In the example above, the template text when loaded into the word processor appears as follows:
    First Last
    e-mail Address
    Subject: Subject
    
    Dear First:
    
    but after a merge operation the text appears as:
    Cynthia Smith
    csmith@somewhere.com
    Subject: Product questions
    
    Dear Cynthia:
    
  4. Create an HTML file that instantiates the InfoBusBridge and the WP applets, and contains JavaScript code to perform the merge operation.
    <HTML>
    <HEAD>
            <TITLE>WP merge example</TITLE>
    </HEAD>
    <BODY  BGCOLOR="#FFFFFF">
    
    <PRE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function doMerge()
            {
            // Create a dataitem of merge data to publish on the InfoBus.
            var vec = document.MyIBBridge.createInfoBusBridgeVector();
    
            // Set the values in vector.
            vec.addValue( 0, 0, "First" );
            vec.addValue( 0, 1, "Last" );
            vec.addValue( 0, 2, "EMailAddr" );
            vec.addValue( 0, 3, "Subject" );
            vec.addValue( 1, 0, document.myForm.FirstName.value );
            vec.addValue( 1, 1, document.myForm.LastName.value);
            vec.addValue( 1, 2, document.myForm.EMail.value );
            vec.addValue( 1, 3, document.myForm.Subject.value );
            //and so on.
    
            // Publish the vector to the InfoBus.
            document.MyIBBridge.publishVectorToBus( "wpmerge", vec );
    
            // Tell WP applet to initiate the merge.
            document.MyWP.mergeFirstRecordFromInfoBus( "wpmerge" );
    
            //Assume that there are nine more rows of data to be merged.
            for (i=1;i<10;i++)
              {
              //Do something useful with the merged data,
              // for example, print or save the current document to a file.
              //Then repeat the procedure. 
              document.MyWP.MergeNext( );
              
              }
            }
    // -->
    </SCRIPT>
    </PRE>
    
    <APPLET NAME="MyIBBridge" CODE="lotus.ibtools.InfoBusBridge"
                CODEBASE="..\.."
                WIDTH=1 HEIGHT=1> 
    </APPLET>
    <APPLET NAME="MyWP" CODE="lotus.wp.WordProcessor"
       CODEBASE="..\.."
       WIDTH=500 HEIGHT=450>
       <PARAM NAME="URL" VALUE = "myserver.com\docs\WPTemplates\mywptemplate.html">
    </APPLET>
    <FORM NAME = "myForm">
    <INPUT TYPE="button" VALUE="Merge" ONCLICK="doMerge()">
    </FORM>
    </BODY>
    </HTML>
    

    See also
    mergeNextRecord method