Using the SData API From Client-Side Javascript in the Infor CRM Web Client

It’s a good practice when customizing the Infor CRM (Saleslogix) Web client to always be aware of how your customizations will impact performance. A good way to make sure that the client performs quickly is to offset work to the client, instead of always using server-side code. Using the SData API in the web client is a pretty easy task and will make things operate more quickly, in many cases, since you’re moving the task to the browser rather than another postback to the server.

SData in the Web Client

First of all, when you use SData in the web client, you’re technically not using the SData portal. There is a handler in the web client named slxdata.ashx that will handle all of the SData calls (which is implemented in Sage.Integration.Web.SageIntegrationHandler in Sage.Integration.Web.dll). However, that doesn’t really matter much when using it. You still use it the exact same way. Even the SData URLs are formed the same, with the exception of the start of the url. Instead of looking like this:

http://myserver/sdata/slx/dynamic/-/contacts?where=LastName like 'Abb%'&format=json

It will look like this (“sdata” replaced with “slxclient/slxdata.ashx”):

http://myserver/slxclient/slxdata.ashx/slx/dynamic/-/contacts?where=LastName like 'Abb%'&format=json

I really just point this out for informational purposes only. It makes no difference to how you consume SData in the client. You’ll still use the SDataJavaScriptClientLib (assuming you’re consuming via client-side code as this article discusses). One big difference when using SData in the web client is that you don’t need to provide the user credentials to authenticate since there is a registry service that will provide you a reference to the SData service using the same authenticated credentials as the currently logged in user.

Consuming SData in the Web Client

Let’s take a look at some code. In this sample, we will get the SData entity for the current contact record.

// get the current record context so we can get the current contact ID
var context = Sage.Services.getService('ClientEntityContext').getContext();
var contactId = context.EntityId;

// get a reference to the SData service. This will already use the same 
// credentials as the currently logged in user. We'll get a "dynamic" 
// service (as opposed to a "system" service)
var service = Sage.Data.SDataServiceRegistry.getSDataService('dynamic');
    
// request the contact via SData 
var request = new Sage.SData.Client.SDataSingleResourceRequest(service)
    .setResourceKind('contacts')
    .setResourceSelector('"' + contactId + '"')
    // protip: always specify a select param instead of just requesting the entire entity,  
    // unless you really need it all, to cut down on the size of the payload. This will  
    // make a huge difference in the speed of the request.
    .setQueryArg('select', 'LastName,FirstName,Address/PostalCode');

request.read({
    success: function (entity) {
        // now get the needed contact values and do whatever you need with them
        var lastName = entity.LastName, 
            firstName = entity.FirstName, 
    	    addressId = entity.Address.$key;
            // etc...
        alert('Do something here for contact: ' + firstName + ' ' + lastName); 
        console.log(entity);
    },
    failure: function (result) {
        Sage.UI.Dialogs.showError(result);
    }
});

That’s it. As I mentioned, the only thing that really differs from using SData normally, is getting the service reference from the registry service with the current users authentication details already. From there, it’s just the same. You’d be surprised how stepping outside the traditional web client postbacks can improve the user experience at times.

ABOUT THE AUTHOR

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.

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) news and product updates!

You have Successfully Subscribed!