Record Examples

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.

Example 1. Creating a new Record

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:

Example 2. Appending Values to Records

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:

Example 3. Removing Values from Records

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:

Example 4. Accessing Record Values

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:

Example 5. Record Status

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:

Example 6. Handling Record Deletion

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: