AJAX call to retrieve data from a View

Hi All, I'm using Jeff's example snippet of making an Ajax call to retrieve two fields from the Company entity. However if I want to retrieve several fields from different tables - would it be possible to make that call via a VIEW rather than a single table? I have tried the following with no luck. crm.sdata({ entity: "vSummarycompany", id: companyID, success: successCompany }); Please help?? regards Adrian
  • 0

    Hi,

    Apologies for the late answer on this one.

    You mightn't be able to use vSummaryCompany itself, as it's not SDATA-enabled as such, but in general you can enable custom views for SDATA, and they'll work with the crm.sdata function.

    As a test, I've created a view that queries similar data to vSummaryCompany:

    CREATE VIEW vTestSDATACompany AS

    SELECT RTRIM(ISNULL(Pers_FirstName, '')) + ' ' + RTRIM(ISNULL(Pers_LastName, '')) AS Pers_FullName,

    RTRIM(ISNULL(User_FirstName, '')) + ' ' + RTRIM(ISNULL(User_LastName, '')) AS User_Name,

    vAddress.*,

    vPersonPE.*,

    vCompanyPE.*,

    Users.*

    FROM vCompanyPE

    LEFT JOIN vAddress ON Comp_PrimaryAddressId = Addr_AddressId

    LEFT JOIN vPersonPE ON Comp_PrimaryPersonId = Pers_PersonId AND Pers_Deleted IS NULL

    LEFT JOIN Users ON Comp_PrimaryUserId = User_UserId

    This can then be accessed using the following:

    // ID 43 is 3G Homes

    var companyid = 43;

    function successCompanySingle (crmRecord) {

    alert("This company has a name of: " + crmRecord.comp_name);

    }

    crm.sdata({

    entity: "vTestSDATACompany",

    id: companyid,

    success: successCompanySingle

    });

    This works fine. If you're in any doubt as to whether the view is SDATA-enabled, you can access it through a browser, as follows:

    crm-server/.../vTestSDATACompany

    The above was tested in v7.2d. You might find that the view isn't available as an SDATA view using the URL above; this returns a "Resource kind does not exist" error, and would generally be caused by a failure to refresh the Tomcat metadata. You'd want to check out your ewaresystem.log to see if the HTTP request to refresh the metadata coming from the eWare.dll is successful. If you're just running a test environment, then doing an IIS reset should resolve this.

    All the best,

    Rob