Contents Hide
A record may be likened to a row on a table, where a table may be seen as a record set, us to create records to pass to BrightServer, these records need to be constructed. The methods to achieve this are demonstrated below.
record = new Record();
// create a new record with the ADDED status
record = new Record(Record.ADDED);
data = new Vector();
data.add(12);
data.add("Bananas");
data.add("Pineapple");
record = new Record(Record.MODIFIED, data);
Note:
The first instantiation of a record will create an empty record with status UNKNOWN
The second will create an empty record with the status ADDED
data is a new vector of objects which can be used to initialise a new record
Values may be appended to field values using the Record.add() method. Furthermore, Record.set() may be used to change values within a record.
// create a new record with the ADDED status
record = new Record(Record.ADDED);
// Append Values
record.add("Bananas");
record.add("Pineapple");
record.add(42);
ScriptSession.info(record.toString());
// Change Value
record.set(1, "Apple");
ScriptSession.logInfo(record.toString());
Note:
The index used for Record.set() cannot equal or exceed the size of the record
The output into the BrightServer log will be:
12:34:56 INFO [User Script:Script1] Record [Status=1, Content=[Bananas, Pineapple, 42.0]]
12:34:56 INFO [User Script:Script1] Record [Status=1, Content=[Bananas, Apple, 42.0]]
Record.toString() prints out a string listing in the following format:
"Record [Status=<STATUS> Content=<RECORD_CONTENT>]"
Values may be appended to field values using the Record.remove() method. Following the last example:
// print the current contents of the record
ScriptSession.logInfo(record.toString());
// Remove Value
record.remove(1);
ScriptSession.logInfo(record.toString());
Note:
The index used for Record.remove() cannot equal or exceed the size of the record
The output into the BrightServer log will be:
12:34:56 INFO [User Script:Script1] Record [Status=1, Content=[Bananas, Apple, 42.0]]
12:34:56 INFO [User Script:Script1] Record [Status=1, Content=[Bananas, 42.0]]
Record.toString() prints out a string listing in the following format:
"Record [Status=<STATUS> Content=<RECORD_CONTENT>]"
Values within a record may be accessed using the Record.get() method.
// create a new record with the ADDED status
record = new Record(Record.ADDED);
// populate record
record.add("Bananas");
record.add("Pineapple");
record.add(42);
// test the Record.get() method
ScriptSession.logInfo(record.get(2));
ScriptSession.logInfo(record.get(0));
ScriptSession.logInfo(record.get(1));
Note:
The output into the BrightServer log will be:
12:34:56 INFO [User Script:Script1] 42
12:34:56 INFO [User Script:Script1] Bananas
12:34:56 INFO [User Script:Script1] Pineapple
Typically featured in Sync Writers, records will be retrieved from BrightServer with a status which determines how the record is to be synchronised between the device and the script.
| Int Value | Constant | Description |
| 0 | Record.UNKNOWN | |
| 1 | Record.ADDED | Marks that a record needs to be added |
| 2 | Record.MODIFIED | Marks that a record needs to be modified or updated |
| 3 | Record.DELETED | Marks that a record needs to be deleted |
record = rs.get(j) ;
if (record.getStatus() == Record.UNKNOWN)
{
ScriptSession.logInfo("Code to deal with unknowns") ;
}
if (record.getStatus() == Record.ADDED)
{
ScriptSession.logInfo("Code to write record") ;
}
if (record.getStatus() == Record.MODIFIED)
{
ScriptSession.logInfo("Code to modify record") ;
}
if (record.getStatus() == Record.DELETED)
{
ScriptSession.logInfo("Code to delete record") ;
}
Note:
The above fragment would typically be found in a write method in the Sync Writer framework, where rs is the current record set being parsed through the data .
Lines of code with ScriptSession.info(<string>); are essentially placeholders for actual code in the situations provided.
record = rs.get(j) ;
if (record.getStatus() != Record.DELETED)
{
ScriptSession.logInfo("PK = " + record.get(0));
ScriptSession.logInfo("FIELD1 = " + record.get(1));
ScriptSession.logInfo("FIELD2 = " + record.get(2));
ScriptSession.logInfo("FIELD3 = " + record.get(3);
}
if (record.getStatus() == Record.DELETED)
{
ScriptSession.logInfo("DELETE = record.get(0));
}
Note:
Any record whose status is set to delete will not have other fields accessible. Therefore, records may be deleted only using the primary key. Therefore, the top most branch would fail for Record.DELETED records.