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
   Preserving Custom Roles, Secured Actions, and Assignments in Infor CRM (formerly Saleslogix) Upgrades
When upgrading between levels of Infor CRM one of the tasks that is commonly needed is to run a batch/exe
Posted on Dec 16, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Easily Showing and Hiding Tabs at Runtime in Infor CRM (Saleslogix)
Showing and hiding tabs in the Infor CRM (Saleslogix) client should be an easy thing. It should be someth
Posted on Dec 16, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Checking Infor CRM (Saleslogix) Picklists for valid data
This week I received a question about a particular picklist. One of the picklist items, when chosen, wou
Posted on Dec 05, 2014 by Dale Richter to Infor CRM Questions & Answers
 
   InforCRM (formerly SalesLogix) Web Issues with McAfee VSE 8.8 Patch 4
We have see an issue with SalesLogix v8.0 and v8.1 web clients where randomly all users are bounced due t
Posted on Dec 05, 2014 by Mark Duthoy to SalesLogix Support
 
   Avoiding the Dirty Data Message When Programatically Redirecting to a Record in Infor CRM (Saleslogix)
In my last post I wrote about using the OnClientClick property of a control (or button) to run JavaScript
Posted on Dec 02, 2014 by Ryan Farley to Ryan Farley's Blog
 
Comments

 

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

svc.Initialize();

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

Still it got me going.

Thanks

Klemens

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.

-Ryan

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 1.2.2.1335 Since we had problems with the lastest one 1.3.0.1456.

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!!

Lluís

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

try

{

b.Create();

c.Read();

d.Update();

e.Delete();

}

catch (SDataServiceException e)

{

string errorMessage = e.Diagnosis.Message;

}

September 13, 2011 3:36 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 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