Sample Codes — C#

Note that “limit” attribute is always required, but for the sake of saving space, only the first example shows the loop which correctly gets multiple batches of data.

Read with equal to Method — C#

Read the fields ID, nickname, updated for users with nickname ‘jsmith'.

            ReadResult[] results;
ReadRequest rr = new ReadRequest();
rr.type = "User";
rr.method = "equal to"; //return only records that match search
criteria
rr.fields = "id, nickname, updated"; //specify fields to be returned. //Specify search criteria
oaUser user = new oaUser();
user.nickname = "jsmith";
rr.objects = new oaBase[1] { user }; //pass in one object with search
criteria int index = 0; //Starting index
const int LIMIT = 1000; //Return maximum of 1000 records per request
do {
   // Limit attribute is required.
   OA.Attribute attr = new OA.Attribute();
   attr.name = "limit";
   attr.value = String.Format("{0}, {1}", index, LIMIT);
   rr.attributes = new OA.Attribute[] { attr };
   results = _svc.read(new ReadRequest[] { rr });
   if (results != null && results.Length > 0 && results[0].errors !=null) {
      foreach (oaError err in results[0].errors) { 
         Debug.WriteLine(string.Format("Error {0} - {1}", err.code,err.text));
      } 
   } 
   // get next 1000 records
   index += LIMIT;
} while (results[0].objects != null && results[0].objects.Length > 0); 

          

Read with not equal to Method — C#

Read ID, nickname, and updated fields for users that do not match certain search criteria.

            ReadRequest rr = new ReadRequest();
rr.type = "User";
rr.method = "not equal to"; //return only records that do not match search criteria
rr.fields = "id, nickname, updated"; //specify fields to be returned

oaUser user = new oaUser();
user.nickname = "jsmith";
rr.objects = new oaBase[1] { user }; //pass in one object with search criteria

// Limit attribute is required.
OA.Attribute attr = new OA.Attribute();
attr.name = "limit";
attr.value = "500";
rr.attributes = new OA.Attribute[] { attr };

ReadResult[] results = _svc.read(new ReadRequest[1] { rr }); 

          

Read Custom Field Definitions with equal to Method — C#

Read all custom fields associated with project record type.

            ReadRequest rr = new ReadRequest();
rr.method = "equal to";
rr.type = "CustField";

oaCustField cf = new oaCustField();
cf.association = "project"; // custom field association

// Limit attribute is required.
OA.Attribute attr = new OA.Attribute();
attr.name = "limit";
attr.value = "500";
rr.attributes = new OA.Attribute[] { attr };

rr.objects = new oaBase[] { cf };
ReadResult[] results = _svc.read(new ReadRequest[] { rr }); 

          

Read Custom Field Values with custom equal to Method — C#

Read custom field values for a given project.

            ReadRequest rr = new ReadRequest();
rr.method = "custom equal to"; //all custom fields associated with the
project are returned
rr.type = "Project"; //See table of objects that have custom field
support

oaCustomField cf = new oaCustomField();
cf.id = "238"; // ID of the project
rr.objects = new oaBase[] { cf };

OA.Attribute attr = new OA.Attribute();
attr.name = "limit";
attr.value = "500";
rr.attributes = new OA.Attribute[] { attr };

ReadResult[] results = _svc.read(new ReadRequest[] { rr }); //
returns name/value pairs. 

          

Read Not Exported Charges with all Method — C#

Read all slips and add a filter to retrieve not yet reported records only.

            ReadRequest rr = new ReadRequest();
rr.method = "all";
rr.type = "Slip";

OA.Attribute attrLimit = new OA.Attribute();
attrLimit.name = "limit";
attrLimit.value = "500";

OA.Attribute attrFilter = new OA.Attribute();
attrFilter.name = "filter";
attrFilter.value = "not-exported";

rr.attributes = new OA.Attribute[] { attrLimit, attrFilter };

// Tell the server we are filtering on import_export records created
by MY_APP
oaImportExport importExport = new oaImportExport();
importExport.application = "MY_APP";
rr.objects = new oaBase[] { importExport };

ReadResult[] results = _svc.read(new ReadRequest[] { rr });

// Mark the slip with ID = 4 as exported by the application MY_APP on 4/1/2011.
// After doing this, the next read call with not-exported filter
attribute will not export this record.
oaImportExport exportRecord = new oaImportExport();
exportRecord.application = "MY_APP";
exportRecord.type = "Slip";
exportRecord.id = "4";
exportRecord.exported = "2011-04-01 00:00:00";

UpdateResult[] ur = _svc.upsert(new OA.Attribute[] {}, new oaBase[] { exportRecord }); 

          

Read Not Exported Expense Reports with all Method and Date Filter — C#

Request envelope records that were approved in a certain date range and were not exported yet.

Note:

Multiple filters can be used. They should be CSV concatenated in one single filter attribute. For example, to retrieve all timesheet entries in a certain date range for approved timesheets only, attrFilter.value should be “newer-than, older-than, approved-timesheets”.

            ReadRequest rr = new ReadRequest();
rr.method = "all";
rr.type = "Envelope";

//Filter by date range and by the special not-exported flag
OA.Attribute attrFilter = new OA.Attribute();
attrFilter.name = "filter";
attrFilter.value = "newer-than,older-than,not-exported";

//Name of the field to apply date filter to
OA.Attribute attrField = new OA.Attribute();
attrField.name = "field";
attrField.value = "date_approved,date_approved";

OA.Attribute attrLimit = new OA.Attribute();
attrLimit.name = "limit";
attrLimit.value = "500";

rr.attributes = new OA.Attribute[] { attrFilter, attrField, attrLimit};

// set newer-than filter date
oaDate dateNewer = new oaDate();
dateNewer.year = "2008";
dateNewer.month = "10";
dateNewer.day = "17";

// set older-than filter date
oaDate dateOlder = new oaDate();
dateOlder.year = "2008";
dateOlder.month = "10";
dateOlder.day = "17";

rr.objects = new oaBase[] { dateNewer, dateOlder };
ReadResult[] results = _svc.read(new ReadRequest[] { rr }); 

          

Read with equal to Method and Lookup by Custom Field Value — C#

            ReadRequest rr = new ReadRequest();
rr.method = "equal to";
rr.type = "Project";

//Get the first 100 records only
OA.Attribute attrLimit = new OA.Attribute();
attrLimit.name = "limit";
attrLimit.value = "100";
rr.attributes = new OA.Attribute[] { attrLimit };

//Get only records with custom field ProjectStatus set to "Yellow"
//Specify additional values in comma delimited list, e.g.
"Yellow,Green,Red"
//Provide empty string to get records that don't have any value set,
//e.g. filter.ProjectStatus__c = "";
//If the custom field type is Date provide default date to get records
that
//have no value, e.g. filter.ProjectStatus__c = "0000-00-00";
oaProject filter = new oaProject();
filter.ProjectStatus__c = "Yellow";
rr.objects = new oaBase[] { filter };

ReadResult[] results = _svc.read(new ReadRequest[] { rr }); 

          

Read with Multiple equal to Methods Combined with Explicit OR Condition — C#

Search for all Bookings for users with ID 5 or 6.

            ReadRequest rr = new ReadRequest();
rr.method = "equal to, or equal to";
rr.type = "Booking";

OA.Attribute attrLimit = new OA.Attribute();
attrLimit.name = "limit";
attrLimit.value = "100";
rr.attributes = new OA.Attribute[] { attrLimit };

oaBooking book1 = new oaBooking();
book1.userid = "3";

oaBooking book2 = new oaBooking();
book2.userid = "10";

rr.objects = new oaBase[] { book1, book2 };
ReadResult[] results = _svc.read(new ReadRequest[] { rr }); 

          

Single Read() Call with Multiple Read Requests — C#

In many cases, It is not possible to retrieve all objects required in a single read request.

You should batch multiple read requests in a single read() call when the integration logic allows it.

The following code samples executes multiple read requests in a single call to the server, and counts as one single transaction against your daily account limit.

            int[]idsList = new int[] { 1, 22, 1633, 32, 9, 28, 39 };
ReadRequest[] readRequestsList = new ReadRequest[ IDs.Length];
for (int i = 0; i < 1000 && i <idsList.Length; i++) { 
   ReadRequest rr = new ReadRequest(); 
   rr.type = "Slip";
   rr.method = "equal to"; 
   OA.Attribute attrLimit = new OA.Attribute(); 
   attrLimit.name = "limit"; 
   attrLimit.value = "1"; 
   rr.attributes = new OA.Attribute[] { attrLimit };
   oaSlip slipToRead = new oaSlip(); 
   slipToRead.id =idsList[i].ToString(); 
   rr.objects = new oaBase[] { slipToRead }; 
   readRequestsList[i] = rr;
}
ReadResult[] results = _svc.read(readRequestsList);