Show:

sdata Methods

This class provides methods that allow you to create client-side SData requests.

Item Index

Methods

sdata
(
  • options
)

Makes SData calls to Sage CRM's SData provider.

Parameters:

  • options Object

    Specifies a set of key-value pairs used to configure the format of the SData request.
    This parameter has the following options:

    • entity String

      Specifies the entity to search. This option is mandatory when you use the url option.

    • [id] String | Number optional

      Specifies the ID (a number or string) of the record to retrieve.

    • [where] String optional

      Specifies the where clause of the query.

    • success Function

      Specifies the function to run when the SData query returns a feed.

    • [error] Function optional

      Specifies the function to run if an error has occurred while retrieving the SData request.

    • [count] Function optional

      Specifies the number of records the service returns in a page.

    • [startIndex] Function optional

      Specifies the index of the first record returned in this feed. Index starts at 1.

    • [url] Function optional

      Specifies the function to run if there is an error retrieving the SData request.

    • [orderBy] Function optional

      Specifies the field by which to sort the results.

    • [async] Boolean optional

      Specifies 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:

  • link. An array of standard SData links. For details, see Feed-level Links in the SData Specification.
  • totalResults. A string containing the complete results of the query.
  • itemsPerPage. A string describing the amount of desired records in the feed. This number is usually the value of the count parameter when this parameter is present in the URL. For more information, see Paging Information in the SData Specification.
  • startIndex. Index of the first resource returned in this feed. Index starts at 1, not 0.
  • updated. The time when the feed was produced.
  • title. A friendly title for the feed.
  • id. Feed URL.
  • isLast. A Boolean value that describes whether the current page of results is the last in a feed.
  • nextLink. Returns a URL containing a link to the next page of results.
  • 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
    )

    Converts a date string in the ISO format to a JavaScript Date object.

    Parameters:

    • Date String

      Specifies 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
    )

    Converts a JavaScript Date object to a date string in the ISO format, so that it can be used in SData queries.

    Parameters:

    • Date String

      Specifies 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;
            }
        });

    © Copyright Sage Technologies. All rights reserved.