Page 1 of 1

Unable to use "data" param in success event and "Run Javascript" action of service response of a db service

Posted: Sun Oct 05, 2014 12:24 am
by Lux Smith

data.length or data[0]. returns undefined in the success event and "Run Javascript" action of service response of a db service.

It seems to be working fine before the upgrade of the latest release. Has anything changed. What does "this" refer to in "function ( data ) { / this - current element"?


Unable to use "data" param in success event and "Run Javascript" action of service response of a db service

Posted: Sun Oct 05, 2014 6:55 am
by Alena Prykhodko

Hello Lux,

Could you please provide more details? What code do you run? Show us screen shots.

Have you tried rolling back your app to the old builder version?

:: http://devcenter.appery.io/documentat...

Does the behavior persist?


Unable to use "data" param in success event and "Run Javascript" action of service response of a db service

Posted: Fri Dec 12, 2014 5:16 pm
by Matt6607699

I am getting this same issue. I run a google places search that returns multiple results. on success JS I run:

var len = data.length;
alert(len);

This keeps alerting(also tried to console.log();) undefined.

I can however access the data. for example:
alert(JSON.stringify(data.results[0].photos[0].photo_reference));
This alerts the photo reference number correctly.

Is there another way to get data.length?
I used data.length for a loop in the same success event JS and that doesn't work either.


Unable to use "data" param in success event and "Run Javascript" action of service response of a db service

Posted: Mon Dec 15, 2014 12:02 am
by Yurii Orishchuk

Hi Matt,

"data" variable - is just a parsed response from your service. If service will returns Object - it will be JS object. If you service returns an Array - it will JS array.

"data.length" - have only "Array" type of the JS object.

So in your case, your service returns "Object" this type of object does not have ".length" property.

But in your JS object there is "result" field - that is seems to be an array. So if you want to get length of this array - you can use following JS code:

pre

console.log("length = " + data.results.length);

/pre

Regards.


Unable to use "data" param in success event and "Run Javascript" action of service response of a db service

Posted: Tue Dec 16, 2014 3:14 pm
by Matt6607699

Excellent, Thank you very much