cancel
Showing results for 
Search instead for 
Did you mean: 

Select a column given by parameter via XSDS

Former Member
0 Kudos

Hi,

I'm new to SAP HANA, and know I'm facing this problem:

I've been given an entity declared like this:

Entity translation {

key id: Integer64 not null;

en: String(5000);

fr: String(5000);

de: String(5000);

it: String(5000);

es: String(5000);

zh: String(5000);

ko: String(5000);

ru: String(5000);

jv: String(5000);

ar: String(5000);

pt: String(5000);

ja: String(5000);

};

So you get the id and depending on the language that is been used, you choose one column or other

For example: we are using the language "english" (en). So I've got a global variable: var lang = "en";

Is it possible to perform a select with XSDS like this, so I choose the column i want to display depending on the variable "lang"?

        var XSDS = $.import("sap.hana.xs.libs.dbutils", "xsds");

        var MyEntity = XSDS.$importEntity("package", "model.translation");

       

        // retrieve entity instance

   

        var query = MyEntity.$query().$where(MyEntity.id.$eq(1));

       

        var results = query.$execute();

       

        // process result

        if (results.length > 0){

            $.response.setBody(JSON.stringify(results[0].lang));

        }

Of course this code is wrong, but is just so you canget the idea...

Thank you very much

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

Hello Luis,

you can access the property by using the bracket notation in case your property name is stored in a variable.

For your example: results[0][lang]

Best Regards,

Florian

Former Member
0 Kudos

OMG! My mistake was writing a dot between both brackets...

results[0].[lang]

what an idiot...i've used this in other files...

thanks a lot!

Best regards,

Luis

Answers (0)