Storing Custom Node Data with oScript
made by the Easy DIffusion AI

Storing Custom Node Data with oScript

This example adds some custom data to a stored adress field. It uses the old legacy gui of the content server (although you can easily adopt this mechanism to smartUI)

Content Server automatically maintains all of the standard Content Server system data (for example, item name, item comments, and the modified date of an item) for an LLNode object. If you want to store custom data, you can use the DTree table. The ExtendedData column in the DTree table stores the custom data.

The ExtendedData column is a long text type that is indexed and searchable. You can access it through OScript, and it must contain an Assoc with elements that can be of any type or value, including List or Assoc.

These are the steps:

Creating Data Entry Fields on the Add Item Page

You can allow Content Server users to enter address information by adding data entry fields to the standard Content Server Add Item page for your custom node. The Add Item page is generated by examining the contents of the fHTMLCreate feature (which contains the name of a WebLingo file) of your WebNode object and, if defined, inserts the HTML generated by that file in the Add Item page.

WebLingo files contain standard HTML and embedded OScript that allows you to access your module's objects.

This section teaches you how to add six fields to the Add Item page: Last Name, First Name, Street Address, City, State, Zip Code.

To create the addresscreate.html file:

1.????? In the Web Address object, set the fHTMLCreate feature to addresscreate.html.

2.????? Create an HTML file named addresscreate.html, and save it in the module's html directory (for example, c:\opentext\module\addressbook_9_1_0\html).

3.????? Add the following code to the addresscreate.html file: ;;webscript addresscreate This webscript directive indicates that the addresscreate.html file contains OScript code.

4.????? Add the following code:

 <TR> 
<TD> &nbsp;Last Name:</TD> <TD><input type = "text" Name = "lastName" size = 18></TD>
</TR>        

This adds a field named Last Name to the Add Item page. It is a text field and is identified by the name lastName. The size of the field depends on the type of information that is intended for the field. In this case, the field size is 18 characters long.

5.????? Copy and edit the previous code sample for each field that you want to add to the Add Item page (see the following example).

<TR>
<TD>
&nbsp;First Name:</TD>
<TD><input type = "text" Name = "firstName" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;Street:</TD>
<TD><input type = "text" Name = "Street" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;City:</TD>
<TD><input type = "text" Name = "city" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;State:</TD>
<TD><input type = "text" Name = "state" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;Zip Code:</TD>
<TD><input type = "text" Name = "zipCode" size = 18></TD>
</TR>
        

6.????? Add the following code to the end of the addresscreate.html file: ;;end You must pair each ;;webscript directive with an ;;end directive.

7.????? Save and close the addresscreate.html file.

Creating the Data Storage Method

The ExtendedData column stores custom node information. The address data that Livelink users enter on the Add Item page is stored in the node's ExtendedData column. The address data is stored as an Assoc with a key-value pair representing each input field.

The Action-Create() method displays the Add Item page. When Livelink users click the Submit button, the Action-Create() method calls the Action-Create2() method which uses the fPrototypeCreate2 list to verify the input arguments and convert them to the proper data type.

To modify a setup script to include the fPrototypeCreate2 list:


1.????? In the Web Address object, open the 1 Setup() script.

2.????? Copy the code from the .fPrototypesCreate2 section of the 0 Setup() script, and then paste it at the end of the Web Address object's 1 Setup() script.

Edit the fPrototypeCreate2 section to add the additional node data elements it must store in the database (shown below):

.fPrototypeCreate2 = \
{ \
{ "parentId", IntegerType, [WebNode_RHParams.ParentID], \
FALSE }, \
{ "name", StringType, [WebNode_RHParams.Name], \
FALSE }, \ 
{ "comment", StringType, [WebNode_RHParams.Comment], \
TRUE}, \
{ "nextURL", StringType, [WebNode_RHParams.URLToReturnTo], \
FALSE }, \
{ "lastName", StringType, 'Last Name', TRUE}, \
{ "firstName", StringType, 'First Name', TRUE}, \
{ "street", StringType, 'Street', TRUE}, \
{ "city", StringType, 'City', TRUE}, \
{ "state", StringType, 'State', TRUE}, \
{ "zipCode", StringType, 'Zip Code', TRUE} \        


Each line of code in the .fPrototypeCreate2 section specifies the input name (the name of the input on your HTML page), its data type, a description of the field, and a Boolean value where TRUE indicates that entering a value in the field is optional.Each line of code in the .fPrototypeCreate2 section specifies the input name (the name of the input on your HTML page), its data type, a description of the field, and a Boolean value where TRUE indicates that entering a value in the field is optional.

3.????? Save, compile, and close the Web Address object's 1 Setup() script.

4.????? Run the Web Address object's 1 Setup() script.

Storing the Data in the Database

Once the address data is fetched from the Add Item page, the database must store the address ?data by overriding certain methods in the LLNode object. For example:

The NodeCreateSubclassPre() method, which sets the values of additional node attributes and performs data validation.

The NodeCreateSubclassPost() method, which stores node data in a secondary table.

To store the new data in the DTree table:

1.????? In the Address object, open the NodeCreateSubclassPre() method.

2.????? Add the following lines of code to the NodeCreateSubclassPre() method after the last variable declarations are made:

Assoc addressData
Dynamic request = createInfo.request        

Declaring these variables creates an Assoc named addressData and a Dynamic variable named request. The request dynamic variable is a local reference to the data obtained from the Add Item page. After Livelink obtains the data from the Add Item page, it stores it in the addressData Assoc.

Add the following code after the last variables are declared:

//Populate the Assoc by assigning values to each field
addressData.lastName = request.lastName
addressData.firstName = request.firstName
addressData.street = request.street
addressData.city = request.city
addressData.state = request.state
addressData.zipCode = request.zipCode        

3.????? Each line assigns the value obtained from the HTML page to the addressData Assoc.

4.????? After you populate the Assoc, add the following code to the NodeCreateSubclassPre() method to update the ExtendedData column (update the tables in the database):

node.pExtendedData = addressData        

5.????? Compile, save and close the NodeCreateSubclassPre() method.

Creating the Data Update HTML Page

The easiest way to view the stored address data is to display the information on the Specific Info page. If the contents of the WebNode object's fHTMLInfo feature are defined, the HTML generated by the file defined in the fHTMLInfo feature is inserted in the Specific Info page. The General Info page also includes an Update button, so that the address information can be modified later.

The updated address data is also stored in a WebLingo file that contains standard HTML and embedded OScript. This WebLingo file is similar to the addresscreate.html file—the main difference is that the update file contains OScript calls to retrieve the stored data from the database instead of saving new data to the database.

To create the addressinfo.html file:

In the Web Address object, set the fHTMLInfo feature to "addressinfo.html" Because the fHTMLInfo feature is type Dynamic by default, you must include quotation marks around the file name to change it to a String type.

Create an HTML file named addressinfo.html, and save it in the module's html directory (for example, <yourmodule>addressbook_9_1_0\html).

Add the following line of code to the addressinfo.html file:

;;webscript addressinfo        

?? This webscript directive indicates that the addressinfo.html file contains OScript code.

Add the following code:

;;oscript{
Dynamic extendeddata = .fRequest.node.pExtendedData
Dynamic lastName, firstName, street, city, state, zipCode        

Add the following code to retrieve the extended data:

if IsDefined( extendeddata )
//if there is data stored in the ExtendedData column retrieve the following
lastName = extendeddata.lastName
firstName = extendeddata.firstName
street = extendeddata.street
city = extendeddata.city
state = extendeddata.state
zipCode = extendeddata.zipCode
else
//If there is no data in the for these fields then leave them blank
lastName = ""
firstName = ""
street = ""
city = ""
state = ""
zipCode = ""
end
;;}        

Add the following HTML code to create the Add Item page with the additional data field Last Name:

<TR>
<TD>
&nbsp;Last Name:</TD>
<TD><input type = "text" Name = "lastName" value = "`lastName`" size = 18></TD>
</TR>        

Copy and edit the previous code sample for each of the fields you want to add to the Add Item page (example below).

<TR>
<TD>
&nbsp;First Name:</TD>
<TD><input type = "text" Name = "firstName" value = "`firstName`" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;Street:</TD>
<TD><input type = "text" Name = "street" value = "`Street`" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;City:</TD>
<TD><input type = "text" Name = "city" value = "`city`" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;State:</TD>
<TD><input type = "text" Name = "state" value = "`state`" size = 18></TD>
</TR>

<TR>
<TD>
&nbsp;Zip Code:</TD>
<TD><input type = "text" Name = "zipCode" value = "`zipCode`" size = 18></TD>
</TR>        

1This creates the fields that are needed to display and modify your address data.

Add the following line of code to the addressinfo.html file:

;;end        

You must pair each ;;webscript directive with an ;;end directive.

Save the addressinfo.html file in your module's html directory (for example, <yourmodule>addressbook_9_1_0\html).

Close the addressinfo.html file.

Creating the Data Retrieval Method

Content Server can store the data in the DTree table, but you must create a method that retrieves the data, and then displays the results in a WebLingo page. To do this, override the default contents of the NodeUpdateSubclassPre() method.

The Action-Info2() method retrieves the Add Item page. The Action-Info2() method uses the fPrototypeInfo2 list to verify the data arguments and display them in an HTML page.

To modify the fPrototypeInfo2 list:

In the Web Address object, open the 1 Setup() script.

Copy the code from the .fPrototypeInfo2 section of the 0 Setup() script, and then paste it at the bottom of the Web Address object's 1 Setup() script.

Edit the fPrototypeInfo2 section to add the additional node data elements the fPrototypeInfo2 feature must retrieve from the database (example below):

.fPrototypeInfo2 = \
{ \
{ "objId", IntegerType, [WebNode_RHParams.ParentID], \
FALSE }, \
{ "comment", StringType, [WebNode_RHParams.Comment], \
TRUE}, \
{ "lastName", StringType, 'Last name', TRUE}, \
{ "firstName", StringType, 'First name', TRUE}, \
{ "street", StringType, 'Street', TRUE}, \
{ "city", StringType, 'City', TRUE}, \
{ "state", StringType, 'State', TRUE}, \
{ "zipCode", StringType, 'Zip code', TRUE}, \
{ "nextURL", StringType, [WebNode_RHParams.URLToReturnTo], \
FALSE } \
}        

Each line of code in the .fPrototypeCreate2 section specifies the input name (the name of the input on your HTML page), its data type, a description of the field, and a Boolean value where TRUE indicates that entering a value in the field is optional.

Save, compile, and close the 1 Setup() script.

Run the 1 Setup() script.

Retrieving Data from the Database

Getting the address data from the database to Livelink requires you to override the NodeUpdateSubclassPre() method which retrieves the values of the additional node attributes and performs data validation.

To retrieve data from the DTree table:

1.????? In the Address object, open the NodeUpdateSubclassPre() method.

2.????? Add the following lines of code to the to the NodeUpdateSubclassPre() method after the last variable declarations are made: Assoc addressData Dynamic request = updateinfo.request

3.????? Add the following code after the last variables are declared:

//Populate the addressData Assoc by assigning values to each field
//This puts the data into the Specific Tab
if Str.Lower(request.objAction) == "info2"
addressData.lastName = request.lastName
addressData.firstName = request.firstName
addressData.street= request.street
addressData.city = request.city
addressData.state = request.state
addressData.zipCode = request.zipCode
        

Each line retrieves the value obtained from the addressData Assoc to the HTML page.

4.????? After you populate the Assoc, add the following code to the NodeUpdateSubclassPre() method to retrieve the ExtendedData column: node.pExtendedData = addressData end

5.????? Compile, save, and close the NodeUpdateSubclassPre() method.

6.????? Save the your OSpace.

Examining Your Progress

At this point, you have added new fields to both the Content Server interface and to the database that allows you to store and retrieve the additional address data. You can test your work by doing the following:

1.????? Restart the Content Server (or the single threaded eclipse)

2.????? Access Content Server with your Web browser and log in.

3.????? Navigate to your Personal Workspace.

4.????? Open an existing address book.

5.????? Click Address on the Add New Item menu.

6.????? Fill in the new fields for the address and click the Add Item button.

7.????? Click Info on the Functions menu of the new address, and then click Specific.

?



要查看或添加评论,请登录

Reiner Merz的更多文章

社区洞察

其他会员也浏览了