sdata Methods
This class provides methods that allow you to create client-side SData requests.
Item Index
Methods
Methods
sdata
(
-
options
)
-
options
Makes SData calls to Sage CRM's SData provider.
Parameters:
-
options
ObjectSpecifies a set of key-value pairs used to configure the format of the SData request.
This parameter has the following options:-
entity
StringSpecifies the entity to search. This option is mandatory when you use the url option.
-
[id]
String | Number optionalSpecifies the ID (a number or string) of the record to retrieve.
-
[where]
String optionalSpecifies the where clause of the query.
-
success
FunctionSpecifies the function to run when the SData query returns a feed.
-
[error]
Function optionalSpecifies the function to run if an error has occurred while retrieving the SData request.
-
[count]
Function optionalSpecifies the number of records the service returns in a page.
-
[startIndex]
Function optionalSpecifies the index of the first record returned in this feed. Index starts at 1.
-
[url]
Function optionalSpecifies the function to run if there is an error retrieving the SData request.
-
[orderBy]
Function optionalSpecifies the field by which to sort the results.
-
[async]
Boolean optionalSpecifies whether the SData call is synchronous or asynchronous.
If this option is omitted, the SData call is asynchronous.
-
Returns:
crmObject
Once returned, the crmObject has the following properties:
Examples:
// Retrieves a company record from within an opportunity and displays that record in an information message.
var companyID = crm.fields("oppo_primarycompanyid").value();
var successCompany = function (crmRecord) {
crm.infoMessage("This opportunity belongs to :" + crmRecord.comp_name);
}
crm.sdata({
entity: "company",
id: companyID,
success: successCompany
});
// Loops through pages of results and executes a function when all results are returned.
// The analyse function is used to process the results of each call.
// The nextLink attribute of the crmRecord object is used to get the next page of results in the feed.
// As this example processes the results, it adds the returned records to the crmData.data array.
// When the isLast attribute is set to true, it means we have received all results and execute the
// crmData.execute on all records returned in the feed.
// Note that when using the url option on the crm.data call, you need to specify the entity type
// you are querying (in this example, it is Company).
var crmData = {};
crmData.data = [];
crmData.execute = function() {
crm.log(crmData.data)
}
var oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
function analyse(crmRecord) {
if (crmRecord.isLast) {
$.each(crmRecord,function(index){
crmData.data.push(crmRecord[index]);
});
crmData.execute();
}
else {
$.each(crmRecord,function(index){
crmData.data.push(crmRecord[index]);
});
crm.sdata({
"url": crmRecord.nextLink,
"entity" : "company",
success: function (crmRecord) {
analyse(crmRecord);
}
});
}
}
crm.sdata({
"entity": "company",
count: 25,
"where": "comp_createddate gt " + crm.sdataQueryDate(oneWeekAgo),
success: function (crmRecord) {
analyse(crmRecord);
}
});
// Returns an object containing company details.
function getCompany(companyID) {
var returnedValue,
successCompany = function (crmRecord) {
returnedValue = crmRecord;
}
crm.sdata({
entity: "company",
async: false,
id: companyID,
success: successCompany
});
return returnedValue;
}
getCompany(44);
sdataDate
(
-
Date
)
-
Date
Converts a date string in the ISO format to a JavaScript Date object.
Parameters:
-
Date
StringSpecifies the date string in the ISO format.
Returns:
Date Object
Examples:
// Converts a text date value in an SData feed to a JavaScript Date object.
crm.sdata({
entity: "company",
id: "4",
success: function(crmRecord) {
var compJSDate = crm.sdataDate(crmRecord.comp_createddate);
}
});
sdataQueryDate
(
-
Date
)
-
Date
Converts a JavaScript Date object to a date string in the ISO format, so that it can be used in SData queries.
Parameters:
-
Date
StringSpecifies the JavaScript Date object.
Returns:
Date Object
Examples:
// Converts a JavaScript Date object to a date string in the ISO format.
var oneWeekAgo = new Date();
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7);
crm.sdata({
entity: "opportunity",
where : "oppo_createddate ge " + crm.sdataQueryDate(oneWeekAgo),
success: function(crmRecord) {
var nummOppos= crmRecord.totalResults;
}
});