sql query in onchange script

Hello,

I have a custom entity and want to get a value (price) from a custom sql-table based on the chosen value of three fields (product, channel, place)

Every time one of the three fields were updated in the screen I need to update the price.

In the onchange scripts of these three fields I can not use server-side commands like "CRM.CreateQueryObj".

How can I solve my problem?

Thank you in advance!

Parents Reply Children
  • 0 in reply to Sage CRM

    That seems to work with standard entities for me now like this:

    var CrmExample = CrmExample || {};
    
    CrmExample.doit = function () {
    var compField = crm.fields("vpos_text1");
    var companyID = 10141;
    var successCompany = function(crmRecord)
    {
    //crm.infoMessage(crmRecord.comp_name);
    compField.title("Status: "+crmRecord.comp_status +"\n Type: "+crmRecord.comp_type);
    document.EntryForm["vpos_text1"].value = crmRecord.comp_status;
    }
    crm.sdata({
    entity: "company",
    id: companyID,
    success: successCompany
    });}

    Now I create a linked table to another database with allowed reading option by sdata.

    When I try to get data from sdata like this 

    http://xxcbx05/sdata/CRMj/sagecrm2/-/KagCRMPreise

    I could not download the data.

    With the SQL Server Profiler I can see that the SQL-Server gets the demand with:

    exec sp_prepexec @p1 output,NULL,N'SELECT COUNT(*) FROM KagCRMPreise WITH (NOLOCK) WHERE null_Deleted IS NULL'

    How can I get data from that linked table in my code?

  • 0 in reply to Nunzio Piazzolla

    Hi Nunzio

    I think you may need to log a support request to establish why the request is failing with a linked database table exposed to SData. 

  • 0 in reply to Sage CRM

    Hello, 

    now I did it to request data from linked table.

    I have to use a view with union like this:

     Building Cross Database Views for Reporting 

    Now I have a problem to query my data.

    When I use this I got a result:

    var CrmExample = CrmExample || {};
    
    CrmExample.doit = function () {
    var compField = crm.fields("vpos_text1");
    var ID = 99;
    var art = 8;
    
    var successCompany = function(crmRecord)
    {
    document.EntryForm["vpos_text1"].value = crmRecord.preis_preis;
    }
    crm.sdata({
    entity: "vkagcrmpreisenew",
    id: ID,
    success: successCompany
    });}

    If I change the sdata parameter like this I get only "undefined".

    var CrmExample = CrmExample || {};
    
    CrmExample.doit = function () {
    var compField = crm.fields("vpos_text1");
    var ID = 99;
    var art = 8;
    
    var successCompany = function(crmRecord)
    {
    document.EntryForm["vpos_text1"].value = crmRecord.preis_preis;
    }
    crm.sdata({
    entity: "vkagcrmpreisenew",
    where: "preis_artnew eq "+art,
    success: successCompany
    });}

    The field "preis_artnew" is an integer.

    What is my fault here?

    Thank you!

  • 0 in reply to Nunzio Piazzolla

    The CRM.sdata method uses the orginal RESTful API called SData.  You can use something like Postman to test the SData endpoints to see whether the call you are trying to make is allowed.

  • 0 in reply to Sage CRM

    Yes Postman gives me a valid result.

  • 0 in reply to Nunzio Piazzolla

    I got it.

    With a where clause the syntax must change to:

    crmRecord[0].preis_preis