Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

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 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 series index

What's This?
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series

Related Content
   Infor CRM (formerly SalesLogix) Administrator Locked Out
I thought I had seen all the issues affecting the datalink but this was a new one. We could not login t
Posted on Jun 18, 2015 by Mark Duthoy to SalesLogix Support
   How do I remove users from my Infor CRM system (formerly SalesLogix)?
I had an Administrator ask me for the steps they needed to take in order to remove a user from the Infor
Posted on May 08, 2015 by Dale Richter to Infor CRM Questions & Answers
   Infor CRM (Formerly Saleslogix) v8.1 update 03 and 05- Uncaught Error Scheduling Contact Processes
 In the Infor CRM (formerly Saleslogix) web client, under the Contact area you have the ability to s
Posted on May 07, 2015 by Kris Halsrud to Kris Halsrud's Blog
   Better Code Organization for Infor CRM (Saleslogix) Mobile Customizations
When customizing the Infor CRM (Saleslogix) Mobile client, it's common for the ApplicationModule to g
Posted on May 05, 2015 by Ryan Farley to Ryan Farley's Blog
   Problem Showing All Area, Category, and Issue Values in Infor CRM (Saleslogix) Mobile And How to Fix
There is an issue with the Infor CRM (Saleslogix) Mobile client where, if you have a large list of Area,
Posted on Apr 24, 2015 by Ryan Farley to Ryan Farley's Blog


Ryan Farley's Blog said:

This page outlines the topics in the SalesLogix SData Series. Use the links below to see each post. As new posts are added to the series they will also be added to this index.

May 31, 2011 12:22 PM

Ryan Farley's Blog said:

In this fourth post in the SalesLogix SData series, I will outline how to write queries for SalesLogix

May 31, 2011 12:59 PM

Klemens said:

Hi there,

great starting point, but ... ;-)

1. One needs to intialize the service before creating a request with


2. The values are not read from the entry variable but from the payload variable.

Still it got me going.



August 22, 2011 5:01 AM

Ryan Farley said:

Hi Klemens, thanks for the comment.

In older versions of SData it was required to call Initialize. That is no longer the case in current versions of SData (Initialize is now marked Obsolete). If you're a few versions back then you'll still need to call Initialize, otherwise you can omit that part now.

Thanks for catching the typo on #2. You're right that should be my payload variable not the entry variable. I've corrected that in the code.


August 23, 2011 2:47 PM

Loogares said:

SData it's working fine in 7.5.4 but we are still using sage.sdata.client version Since we had problems with the lastest one

We are writing a module to comunicate with sharepoint through SDATA, the code it's in c#, we do crud operations fine, no prob with that, it's working as expected :) , but...

I am having hard time trying to retrieve the exception in a catch statement, we can retrieve the server exception (wich is useless) since we need the sdata exception. I have see in the SDATA Protocol Specification that the SDataServiceException is used in the catch statement to retrieve the exception, looks good, but i have no idea in wich namespace i can get SDataServiceException.

Would be great if you can point in wich namespace resides SDataServiceException,

Thanks a lot!!


September 12, 2011 10:21 AM

Ryan Farley said:

Hi Lluís,

I think that might be a typo in the docs. I went back to v1.0 of the SData Client and could only find an SDataClientException, no SDataServiceException (maybe that was a typo because I *think* that is an exception type on the server side)

September 12, 2011 10:50 AM

Loogares said:

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(

"localhost/.../", "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;


September 13, 2011 3:36 AM

Leave a Comment

All contents Copyright © 2015 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register