Tutorial: Creating a Suggestion Query

Creating a Suggestion Query



This tutorial explains how to use the sap.bc.ina.api.impl.inav2.SuggestionQuery class and its result.

First declare your sina variable and define the right dataSource object. To define SAP HANA analytical or attribute views as data source, you need the package name and the object name.

Declaration and definition of sina and data source

var sina = sap.bc.ina.api.sina;
var dataSource = {
    "packageName" : "sap.bc.ina.demos.epm.views",
    "objectName"  : "V_EPM_PRODUCT"
};

In the next step, create the query. In this example, you call the method with all attributes you need to identify suggestions.

Creating the query

var query = sina.createSuggestionQuery({
    dataSource: dataSource,
    top: 5,
    skip: 0,
    attributes: [ 
        "TEXT",
        "CATEGORY",
        "PRICE"
    ],
    searchTerms: "s*"
});

When the query was sent, you get back a result set. The first parameter of the method is the callback function on success. If everything went right, you get one object with your all your results. If not, the second parameter is the callback function on error.

query.getResultSet(function (resSet){
    // --- do something on success
    console.log(resSet);
}, function (jqxhr){
    // --- do something on error
    console.log(jqxhr);
});

The result object looks like this:

resSet = {
    suggestions : [
        0 : {
            label : "Software",
            attribute : "CATEGORY"
            dataSource : {
                schemaName : {
                    label :,
                    value : 
                },
                packageName : {
                    label :,
                    value : 
                },
                objectName : {
                    label :,
                    value : 
                },
                type : {
                    label :,
                    value : 
                },
                label :,
                metaData : undefined
            }
        },
        1 : {
            label : "Scanner",
            attribute : "CATEGORY"
            dataSource : {
                schemaName : {
                    label :,
                    value : 
                },
                packageName : {
                    label :,
                    value : 
                },
                objectName : {
                    label :,
                    value : 
                },
                type : {
                    label :,
                    value : 
                },
                label :,
                metaData : undefined
            }
        }
     ]
}

Complete example

<html>
    <head>
        <meta charset="utf-8">   
        <title>Simple Information Access</title>
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>  
        <script src="/sap/bc/ina/api/sina/release/sap.bc.ina.api.sina.min.js" type="text/javascript"></script>
        <script>
            var sina = sap.bc.ina.api.sina;
            var dataSource = {
                "packageName" : "sap.bc.ina.demos.epm.views",
                "objectName"  : "V_EPM_PRODUCT"
            };
            var query = sina.createSuggestionQuery({
                dataSource: dataSource,
                top: 5,
                skip: 0,
                attributes: [ 
                    "TEXT",
                    "CATEGORY",
                    "PRICE"
                ],
                searchTerms: "s*"
            });

            query.getResultSet(function (rs){
                console.log(rs);
            }, function (jqxhr){
                console.log(jqxhr);
            });
        </script>
    </head>
    <body>
        <!-- do something -->
    </body>
</html>