import com.servicemax.core.Database;
def records = Database.query("SELECT io_uuid, io_name FROM io_basic_object_for_test");
def record = records.get(0);
record.io_name // this is OK
record.io_updated_by // this will cause an exception, because the field was not loaded
def records = Database.query("SELECT * FROM io_basic_object_for_test");
def record = records.get(0);
record.<field> // all the fields will be loaded and available
def records = Database.query("SELECT io_parent.* FROM io_child_smql_test_object");
def record = records.get(0);
record.io_parent.io_name // this will retrieve the parent's record name
def records = Database.query("SELECT io_parent.io_grandparent.* FROM io_child_smql_test_object");
def record = records.get(0);
record.io_parent.io_grandparent.io_name // this will retrieve the grandparent's record name
def records = Database.query("SELECT child.*, child.io_parent.*, io_parent.io_grandparent.* FROM io_child_smql_test_object as child");
def record = records.get(0);
record.io_name
record.io_parent.io_name
record.io_parent.io_grandparent.io_name
def wo = Database.querySingleResult("select svmx_component from svmx_work_order where io_uuid= :io_uuid", [io_uuid:woid]);
wo.svmx_component //retrieve the component from the queried work order
def records = Database.query("SELECT io_uuid, io_name FROM io_basic_object_for_test where io_uuid = :io_uuid", [io_uuid:recordUUID])
def records = Database.query("SELECT io_uuid, io_relational_field_for_test FROM io_relational_child_object_for_test");
def record = records.get(0);
record.io_relational_field_for_test.io_name
record._io_relational_field_for_test
def records = Database.query("SELECT io_uuid, io_name FROM io_relational_child_object_for_test WHERE io_relational_field_for_test.io_name = 'parent name'");
Database.query("select * from io_document where io_related_to[io_page].io_created_by.io_username = 'system'")
Database.query("select io_related_to[io_page].*, io_related_to[io_theme].* from io_document " +
"where io_related_to[io_page].io_url like '%/resources%' or io_related_to[io_theme].io_name like '%ServiceMax%'")
|
|
In the previous example, io_related_to is a dynamic relationship field that is related to multiple targets (such as Page, Theme, and so on). The full identifier of the intended target object is enclosed in square brackets ([ ]).
|
def records = Database.queryAsSet("SELECT io_uuid, io_name FROM io_basic_object_for_test");
def records = Database.queryAsMap("SELECT io_uuid, io_name FROM io_basic_object_for_test");
def records = Database.queryAsList("SELECT io_uuid, io_name FROM io_basic_object_for_test");
def records = Database.queryAsSortedList("SELECT io_uuid, io_name FROM io_basic_object_for_test ORDER BY io_name");
//LIKE clause is case sensitive.
def records = Database.query("SELECT * FROM io_showcase WHERE io_name LIKE '%GE%'")
//ILIKE clause is case insensitive.
def records = Database.query("SELECT * FROM io_showcase WHERE io_name ILIKE '%GE%'")
def records = Database.queryAsSortedList("SELECT io_uuid, io_name FROM io_basic_object_for_test ORDER BY io_name LIMIT 2");
assertEquals 2, records.size() //the LIMIT clause will return only 2 records
def records = Database.queryAsSortedList("SELECT io_uuid, io_name FROM io_basic_object_for_test ORDER BY io_name OFFSET 5");
//the OFFSET clause will cause skipping the first 5 records before beginning to return records
def records = Database.queryAsSortedList("SELECT io_uuid, io_name FROM io_basic_object_for_test ORDER BY io_name LIMIT 10 OFFSET 5");
assertEquals 10, records.size() //the LIMIT clause will return only 10 records and the OFFSET will cause skipping the first 5 records before beginning to return records
def numOfRecords = Database.queryObject("SELECT COUNT() FROM io_child_smql_test_object");
Database.queryInBatches("SELECT io_uuid, io_name FROM io_basic_object_for_test", [:], recordsInMemoryAtTheSameTime,
{ record -> record.io_name //do something with the record here }
);
def records = Database.query("SELECT * FROM io_showcase WHERE translation_contains(io_showcase_string_localized, 'en', 'Hello'")