|
Query
|
The query script definition retrieves data from the external source to include in the remote table. From the Query section, customize the script using the v\_table and v\_query APIs.
Every time a list that contains external data from a remote table is refreshed, the associated query scripts runs.
```javascript
(function executeQuery(v_table, v_query) {
// Parameters:
// v_table - object to record response:
// v_table.addRow({ ... }) - adds a row to the result set.
// keys are the column names of the table definition.
// sys_id must be non-empty and uniquely identify each row.
// the above rule will be strictly enforced for editable tables, and generate warnings for read-only tables.
// sys_id will be supplied to the Update, and Delete scripts to specify the row's identity.
// v_query - the query definition:
// v_query.getEncodedQuery() - encoded querystring
// v_query.getCondition(field) - encoded querystring for the given field (includes field name, operator, and value)
// v_query.getParameter(field) - parameter for the given field (only includes value for equality conditions)
// v_query.isGet() - whether the query is a single get by sys_id
// v_query.getSysId() - parameter for sys_id field
// v_query.isTextSearch() - whether the query contains a text query parameter
// v_query.getTextSearch() - text search query parameter (internal field name 123TEXTQUERY321)
// v_query.getFirstRowWanted() - the first row to include, don't use with caching
// v_query.getLastRowWanted() - the last row to include, don't use with caching
// v_query.setLastErrorMessage(message) - the message is visible from GlideRecord.getLastErrorMessage()
// Sample code:
// try {
// retrieve-rows-from-external-system; // if (there-was-an-error) {
// var message = ...; // v_query.setLastErrorMessage(message);
// return;
// }
//
// for (var row in rows) {
// v_table.addRow(row);
// }
// } catch (ex) {
// var message = ex.getMessage();
// v_query.setLastErrorMessage(message);
// }
})(v_table, v_query);
```
|
|
Insert
|
The insert script definition adds a record to the external source. This script definition is available only if you selected the advanced **Editable** option. From the Insert section, customize the script using the v\_record API.
Every time a record is added to a remote table, the associated insert scripts runs.
```javascript
function executeInsert(v_record) {
// Parameters:
// v_record is a map of field names and values containing the sys_id of the
// record and the fields that need to be inserted in the record on the
// remote system (source of data)
// v_record. - fields in the remote table GlideRecord
// v_record.setLastErrorMessage(message) - signal an error
// Sample code:
// try {
// update-external-system;
// if (there-was-an-error) {
// var message = ...;
// v_record.setLastErrorMessage(message);
// }
// } catch (ex) {
// var message = ex.getMessage();
// v_record.setLastErrorMessage(message);
// }
})(v_record);
```
|
|
Update
|
The update script definition modifies a record in the external source. This script definition is available only if you selected the advanced **Editable** option. From the Update section, customize the script using the v\_record API.
Every time a record is updated in a remote table, the associated update scripts runs.
**Note:** If multiple users update the same record at the same time, the value on the remote system is from the last update call executed.
```javascript
(function executeUpdate(v_record, v_changed_fields) {
// Parameters:
// v_record - a map of field names and values containing the sys_id of the record
// v_record. - fields in the remote table GlideRecord
// v_record.setLastErrorMessage(message) - signal an error
// v_changed_fields - a map of field names and values containing the sys_id of the record
// v_changed_fields. - changed fields in the remote table GlideRecord
// Sample code:
// try {
// update-external-system;
// if (there-was-an-error) {
// var message = ...;
// v_record.setLastErrorMessage(message);
// }
// } catch (ex) {
// var message = ex.getMessage();
// v_record.setLastErrorMessage(message);
// }
})(v_record, v_changed_fields);
```
|
|
Delete
|
The delete script definition removes a record from the external source. This script definition is available only if you selected the advanced **Editable** option. From the Delete section, customize the script using the v\_record API.
Every time a record is deleted from a remote table, the associated delete scripts runs.
```javascript
(function executeDelete(v_record) {
// Parameters:
// v_record - a map of field names and values containing (among others) the
// sys_id of the record that needs to be deleted on the remote system
// v_record. - fields in the remote table GlideRecord
// v_record.setLastErrorMessage(message) - signal an error
// Sample code:
// try {
// update-external-system;
// if (there-was-an-error) {
// var message = ...;
// v_record.setLastErrorMessage(message);
// }
// } catch (ex) {
// var message = ex.getMessage();
// v_record.setLastErrorMessage(message);
// }
})(v_record);
```
|