Summary:

It is possible to make SDATA requests using the client-side API. Some confusion may exist regarding the querying of records using a Where clause, as this function will always return a set of record objects.

More information:

In the following examples, we're using a Car entity, which has a registration number (car_registration) and a model (car_model).

Consider the following code, used to search for a record by its ID.

var carID = "1";

function successCarSingle (crmRecord) {     
    crm.infoMessage("This car is of the following model: " + crmRecord.car_model);
}

crm.sdata({    
    entity: "car",    
    id: carID,    
    success: successCarSingle
});

When searching for a record using its ID, we can reference the result using crmRecord.field_name. This is because only one result is expected - no two records of the same entity will have the same ID.

This is not the case when using a Where clause - potentially more than one record will be returned, even when using an identifier that is notionally unique, like a registration number.

var carRegistration = "00-MN-1234";

function successCarMulti (crmRecord) {

    var strInfo = "";

    $.each(crmRecord,function(index) { 
        strInfo+= "Car " + (index+1) + " has a model of: " + crmRecord[index].car_model + "<br/>";
    });    

    crm.infoMessage(strInfo);
}

crm.sdata({  
    "entity": "car",  
    "where": "car_registration eq " + carRegistration,  
    success: successCarMulti
});

In the second example, we can see that the call to SDATA results in an array of records being returned. In order to reference a specific field, we then need to use crmRecord[index].field_name. If it is known that a single record will be returned (since you're searching using a unique value), you can reference it using crmRecord[0].field_name.


References:

Full documentation on the client-side API is available here:

http://help.sagecrm.com/js-api/