Modifying a Field's Definition |
|
 |
To
rename a field, first navigate to the appropriate .data table on the Web Directory tab, click the Design View tab, select the field you wish to rename, and click the Edit link in the Properties
pane. Note that you must manually update the field name
in any views that are bound to the data table.
You
can't directly change the data type of a field. However,
you can create a new field with a different data type
and copy all the data from your existing field into your
new field. The DataWeb engine will attempt to convert
all of the data to the new type.
First,
create a new field in your data table with the desired
name and type. Then run a script like the following
one to copy data from your original field to the new
field.
Here
is a sample script to copy data from one field to another:
// This function copies all data from one field in a
// table to another existing field in the same table.
// It includes no error checking. Results are logged
// in the web's Log table.
webcall function copycol(sTable, sFromField, sToField)
{
var rs = new Resultset(sTable, "*", "*");
while(rs.next())
{
var oFields = new Object;
oFields[sToField] = rs[sFromField];
try
{
Table.update(sTable, oFields, rs.rowID);
}
catch(e)
{
Script.log("Update failed. RowId=" + rs.rowID,
e.description);
}
}
Script.log("Copy Field", rs.getCount() +
" records copied");
}
//For example, you might run the script as follows:
copycol("Employee", "Home_CellPhone", "HomePhone");
After
you've run the script, delete the old field from your
data table. Finally, in any views that are bound to the
data table, delete references to the old field and add
references to the new field.
|