Retrieving Data via SData for SalesLogix

If you followed my last two posts, you’ll know some basics of what SData is and how to get it to use in your projects. In this post, we will take this a step further and look at how to actually use it, starting with how to query data from SalesLogix.

View the SalesLogix SData Developer series index

Getting a list of Contacts

Let’s start with a basic query. For this example, we will retrieve all contacts whose last name starts with ‘Ab’. Take a look at the code (with comments to walk through each part)

using Sage.SData.Client.Core;
using Sage.SData.Client.Atom;
using Sage.SData.Client.Extensions;
// All requests require an ISDataService which provides
// the service location and user authentication values
ISDataService svc =
    new SDataService("http://localhost/sdata/slx/dynamic/-/", "lee", "");
// Now create the request, passing in the ISDataService we created
// above
var req = new SDataResourceCollectionRequest(svc);
// Tell it which kind of resource we want to access, in this case
// Contacts. Note, this needs to match the values on the SData tab
// of the entity in Application Architect
req.ResourceKind = "Contacts";

// This part is optional (without it we'd be getting ALL contacts).
// This is our where clause, or condition of which contacts we want.
// In this example we want all contacts whose last name starts with
// the value 'Ab'. We need to use the exact property name as defined
// in the entity (case-sensitive).
req.QueryValues.Add("where", "LastName like 'Ab%'");
// Now read the data (or run the query)
AtomFeed feed = req.Read();
// We now have the results in our AtomFeed variable, which is
// basically a list of AtomEntry objects. To get to our data,
// we need to read the payload from each AtomEntry and then we
// can access the values for each field from it's Values
// dictionary. In this example, we'll just write a few fields
// from each contact to the console.
foreach (AtomEntry entry in feed.Entries)
    // Get the payload for this entity
    SDataPayload payload = entry.GetSDataPayload();
    // Now read some values from the payload. Note, the
    // property names you use here need to match the property
    // names defined for the entity (these are case-sensitive).
    string account = payload.Values["AccountName"].ToString();
    string contactName = payload.Values["NameLF"].ToString();
    string title = payload.Values["Title"].ToString();
    Console.WriteLine("{0}, {1} from {2}", contactName, account, title);

That’s not too bad. You do have to access the fields by string name, which means you don’t get intellisense, but at least it’s easy code to write. There are ways to retrieve the schema for an entity which I will look at in a future post.

View the SalesLogix SData Developer series index


Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Hi Ryan, here’s the documentation excerpt where i find the code:

    Handling Errors
    Normal Mode
    1. Construct an ISDataService passing in the SData provider URL
    ISDataService a = new SDataService(
    “http://localhost/sdata/aw/dynamic/-/”, “lee”, “”);
    NOTE: The URL can be passed in or the individual properties of the URL can be set.
    2. Construct a SDataSingleResourceRequests passing in the ISDataService
    var b = new SDataSingleResourceRequest(a);
    var c = new SDataSingleResourceRequest(a);
    var d = new SDataSingleResourceRequest(a);
    var e = new SDataSingleResourceRequest(a);
    3. Setup the Resource Selectors and payloads for create and update
    See – Create, Read, Update, Delete Single Resource
    4. Wrap the calls to Create, Read, Update and Delete in a try-catch block which catches exceptions of type SDataServiceException
    catch (SDataServiceException e)
    string errorMessage = e.Diagnosis.Message;


Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!