Skip to Content

XSJS select query from calculation view with input parameter

Dear friends,

       I am create an XSJS to select data form calculation view with input parameter. In this way ,it works:

var query1 = "SELECT TOP 200 \"SO\", \"ORDER_TYPE\", \"FISCAL\", \"SALE_AREA\", \"COMPANY_CODE\", \"PC\",\"AMOUNT\" " +

              "FROM \"_SYS_BIC\".\"Kevin_Demo.UI5_DEMO1/CAL_SO\" " +

              " ('PLACEHOLDER' = ('$$I_ORDER_TYPE$$', 'YBB1'), 'PLACEHOLDER' = ('$$I_FISCAL_YEAR$$', '2014')) " +

              "GROUP BY \"SO\", \"ORDER_TYPE\", \"FISCAL\", \"SALE_AREA\", \"COMPANY_CODE\", \"PC\",\"AMOUNT\" ";

        But now I want to get the input parameter form my UI5  textfield, then this values will as my placeholder value, how do I write my query ?

         Thanks for your sincerely answer.

Best Regards

Zhang

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jun 29, 2015 at 03:30 PM

    Hello,

    is your question how you prepare the query or how you pass the values from the UI5 source to the XSJS service?

    Preparing the query is straight forward, because it is a string. So if you have the values from the UI5 source you can use it for the preparation (e.g. ... "'PLACEHOLDER' = ('$$I_ORDER_TYPE$$', '" + orderTypeParameterValue + "') ...).

    To have access to the value entered in the UI5 source you have to pass it as parameter to the XSJS service.

    Sample XSJS service call on UI5 side. Here you see that in the "data" attribute a parameter "orderType" is passed to the XSJS service with the entered value (of course you have to replace the placeholder "<entered value>" with the real entered value.

    $.ajax({
           url : "<XSJS service URL>",
           type : "GET",
           data : {"orderType": <entered value> },
           success : function(data){
                // success handling;
           },
           error : function(){
               // error handling
           }
      });
    });
    

    Access to parameter in XSJS service can be done like following:

    var orderTypeParameterValue = $.request.parameters.get("orderType");
    

    The retrieved parameter value you can use to prepare your query string. Please consider that you should do some checks if the parameter is valid (if necessary).

    Best Regards,

    Florian

    Add comment
    10|10000 characters needed characters exceeded

    • Hi,

      your excel is not downloaded (assuming that your XSJS is correct) because the result of the ajax call is handled in the success callback method. So it is not directly interpreted by the browser. You can either implement a logic which does the download in the callback routine, you an implement a button which acts like a link or you go the very easy way and replace your button by a link which calls the excel download XSJS.

      Example for a sap.m.Link which calls a URL on a separate tab:

      - For a JS view.

      var oLink = new sap.m.Link( { "text":"Press me", "target": "_blank", "href": "http://www.google.com"} );
      

      - Same for XML view (which you should prefer).

       <Link text="Press me" target="_blank" href="http://www.google.com" />

      So your excel download XSJS will be called and the result is interpreted by the browser which causes the download.

      Regards,

      Florian