Login / Register  search  syndication  about

          Ryan Farley's Blog

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

Including Nested Payloads with SData for SalesLogix

When you're developing an application or customization using SData for SalesLogix, the fewer trips you make to the server the better. Moving data back and forth across the wire will always be the biggest bottleneck in your code, so making use of embedded payloads will save you some trips by bringing all the data you're after back in one pass.

View the SalesLogix SData series index

What Are Nested Payloads?

Before we get into things, what exactly are nested payloads? Maybe a better term might be "included" payloads. Either way, when you request an entity, or entities, via SData, some part of the entity might be missing, or incomplete. Why? Because of the way that relationships work in the entity model. For example, if you request an Account entity, the AccountManager is a relationship to the User entity. These relationship properties are not included by default in the Account entity unless you tell SData you want those too. If you include related entities, such as the AccountManager, when you get back the Account entity you'll have an nested payload inside the Account payload. So, no need to make another trip back to the server to get the AccountManager. One thing to keep in mind, including related entites will increase the size of the data coming back in the SData feed, this is why these are not included by default, so be sure only include them when you really need them.


Adding An Included Entity In An SData URL

I think it is important to know what the SData URL looks like when doing anything with the client library. I think it helps to understand what you're ultimately ending up with. It also helps to see what the data coming back looks like using your browser by using the URL. When you want to include related entities you simple add an "include" parameter to the query string. For example, consider this URL to get a specific account:

http://localhost:3333/sdata/slx/dynamic/-/accounts('AA2EK0013023')

Now, to include the AccountManager entity as an embedded payload, add to the URL as follows:

http://localhost:3333/sdata/slx/dynamic/-/accounts('AA2EK0013023')?Include=AccountManager

To include additional related entities, such as all Contact entities for the Account, add that as well:

http://localhost:3333/sdata/slx/dynamic/-/accounts('AA2EK0013023')?Include=AccountManager,Contacts

Now when the Account entity comes back it will include an nested payload for the AccountManager, but also a collection of payloads for each Contact related to the Account - all in one trip to the server.


Including Related Entities Using the C# Client Library

Now that you know what the URL with includes look like, let's take a look at how to write the code and how to use the nested payloads. We'll use the example above to get a single Account and include the AccountManager and all related Contacts for the Account as nested payloads.

using Sage.SData.Client.Atom;
using Sage.SData.Client.Core;
using Sage.SData.Client.Extensions;


//...


var service = new SDataService("http://localhost:3333/sdata/slx/dynamic/-/", "admin", "");

 
var req = new SDataSingleResourceRequest(service);
req.ResourceKind = "Accounts";
req.ResourceSelector = "'AA2EK0013023'";

 
// We have to include the entities we want returned as nested payloads
req.QueryValues.Add("include", "Contacts,AccountManager");

 
// We can access normal properties of the Account
var string accountName = payload.Values["AccountName"].ToString();

 
// Now get nested payload for AccountManager
var accMgrPayload = (SDataPayload)payload.Values["AccountManager"];
// We can access properties in the AccountManager payload
var accMgrUserName = accMgrPayload.Values["UserName"].ToString();

 
// Get nested Contacts collection of payloads
var contactsPayloadCollection = (SDataPayloadCollection)payload.Values["Contacts"];
// And iterate through each one
foreach (SDataPayload contactPayload in contactsPayloadCollection)
{
    // We can access properties in this Contact payload
    var contactLastName = contactPayload.Values["LastName"].ToString();
}

The key is to just access the property in the entity and cast it to either an SDataPayload or a SDataPayloadCollection. Cool beans.

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
   Video: Demystifying Infor CRM (Saleslogix) Updates
Watch it now! If you missed yesterdays demo, "Demystifying Infor CRM (Saleslogix) Updates" ,
Posted on Sep 26, 2014 by Brianna Ojard to The Inbox
 
   Thoughts on the Future and Involvement in the Saleslogix/Infor CRM Community
Over the last year and a half I've been working on another product named Contatta. It's a great p
Posted on Sep 25, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Fixing the Orphaning of Salesfusion Data when Converting Leads to Contacts in Infor CRM (Saleslogix)
We have had a couple of client recently come to other with the same problem-When you convert a Lead to a
Posted on Sep 19, 2014 by Kris Halsrud to Kris Halsrud's Blog
 
   Official Infor CRM Acquisition FAQ
What to expect now that Saleslogix is Infor CRM. Like many of you, it will take some time (probably a
Posted on Sep 18, 2014 by Brianna Ojard to The Inbox
 
   ComboFix Kills Saleslogix Sync
ComboFix, a third party malware utility, will alter the Operating system so .qts and .que files will no l
Posted on Sep 12, 2014 by Brianna Ojard to SalesLogix Support
 
Comments

 

Marcel Heuberger said:

Good article. Just something I would like to mention ....

This include works with SingleRessource ('AccountId')

It doesn't work if the request returns a RessourceCollection (query operator 'like').

The following URL works: servername/.../accounts('A6UJ9A001QJ4'))?include=contacts,address,accountmanager

The following URL doesn't work: servername/.../accounts?where accountname like '%value%'&include=contacts,address,accountmanager

So to me it looks like it only works with a SingleResource, not with collections.

I have no idea why the accountmanager cannot be included into the payroll for ResourcesCollection.

December 14, 2011 5:05 AM
 

Ryan Farley said:

Hi Marcel,

It works fine for me using a SDataResourceCollectionRequest. The following code works:

var req = new SDataResourceCollectionRequest(service);

req.ResourceKind = "Accounts";

req.QueryValues.Add("where", "AccountName like 'Ab%'");

req.QueryValues.Add("include", "Contacts,AccountManager");

December 14, 2011 6:36 AM
 

Marcel Heuberger said:

Hi Ryan,

Thanks for your fast response. Looks like you're using the github SDataCSharpClientLib to catch the request, correct?

My SharePoint developer is not using the library and he tries to handle the payroll using comming XMLReader.

But you agree that if you pass the "like" URL as it is into the browser it will throw an error.

Seems that the GitHub Library is very powerfull compared to the common URL request entered in the browser.

Thanks for your time, is much appreciated!

Cheers

Marcel

December 14, 2011 8:00 AM
 

Ryan Farley said:

Hi Marcel,

If you're using a .NET language or Javascript, the libraries provided by Sage do make the work much easier. Either way, those libraries simply form the URL just the same.

I can navigate to this URL for a collection request of Accounts and include nested payloads (like for AccountManager and Contacts)

localhost/.../accounts'Abbott%20Ltd.'&Include=Contacts,AccountManager

This works just fine for me and does not produce any errors.

December 14, 2011 9:42 AM
 

Ryan Farley said:

Marcel, the comments on my blog are munging up the URL :(

The URL part *after* the standard sdata URL stuff:

accounts?where=AccountName eq  'Abbott Ltd.'&Include=Contacts,AccountManager

December 14, 2011 9:52 AM
 

SlxNewbie said:

Hi Ryan, I am using sublogix repository in my applications. And I am trying to use transactionscope in my c# code but it dosent work.I got following error message ..

"The ITransactionLocal interface is not supported by the 'SLXOLEDB.1' provider.  Local transactions are unavailable with the current provider"

so I hard coded my connection string and made the "OE DB Services = -4"from -1 ..so now dsent error but ..the transaction doesnt work as a unit of work if one of the 2 save/deletes fails..and the primary data get commited causing data discrepancy with referntial integrity issues..Any ideas for making this work?

December 14, 2011 12:06 PM
 

Marcel Heuberger said:

Hi Ryan,

No worries, I was guessing the correct URL ;-)

I finally found the issue for me problem. We have Accounts without an AccountManager set (no, don't ask me why, ask my business analyst)

Looks like the Entity Model cannot handle the AccountManager to be NULL. Maybe I can configure SData to allow NULL values for AccountManagers, not quite sure.

Just want to finally share my findings in case somebody else have the same struggle with the AccountManager in SData ;-)

... by the way, I really like your page

Cheers

Marcel

December 15, 2011 3:26 AM
 

Marcel Heuberger said:

The issue have been resolved after applying "Hot Fix Package 01 for Sage SalesLogix Version 7.5.3".

Defect -> 1-77440 SData Feeds need to check for “Nullable” setting on Child Relationships to prevent errors on created, update, and delete actions.

December 15, 2011 9:20 AM
 

Ryan Farley said:

Ah, thanks for sharing that defect. I didn't know that issue existed in 7.5.3.

December 15, 2011 9:46 AM
 

Ryan Farley said:

December 15, 2011 10:06 AM
 

PieInTheSky said:

Hi, when are you going to continue the SData series?

October 18, 2012 4:24 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