Instantiating a record using the .Net SDK
Overview
Once you know its URI (or Record Number) there are a few ways to instantiate a record in the .Net SDK, choose the one that best suites your needs. Each main object type (e.g. Location, History, Hold etc) follows the same pattern seen below.
Constructor
Use the constructor with either the record URI or number. This method will throw a TrimException if the record is not found.
By URI
try { Record record = new Record(database, 900000000); Console.WriteLine(record.Title); } catch (TrimException ex) { Console.WriteLine(ex.Message); }
By record number
try { Record record = new Record(database, "REC_1"); Console.WriteLine(record.Title); } catch (TrimException ex) { Console.WriteLine(ex.Message); }
Database 'find by' method
This will not throw an exception but the resulting object will be null if the Record is not found.
By URI
Record record = database.FindTrimObjectByUri(BaseObjectTypes.Record, 90000000) as Record; if (record != null) { Console.WriteLine(record.Title); }
By record number
Record record = database.FindTrimObjectByName(BaseObjectTypes.Record, "REC_1") as Record; if (record != null) { Console.WriteLine(record.Title); }
By URN
Find by URN can be useful for those occasions when you want to persist a unique identifier for a record (or other object type).
TrimMainObject trimMainObject = database.FindTrimObjectByURN("trim:H1/rec/9000000000"); if (trimMainObject != null) { Console.WriteLine(trimMainObject.Name); }
Written on October 6, 2015