JSRecord.data

Posted by kevin_saunders on 14-Jul-2015 04:20

I am trying to retrieve data from a JSDO. jsdo.hasData() returns true, but this statement returns errors:

jsdo.foreach(function (jsrecord) {
document.getElementById(descField).value = jsdo.jsrecord.data.descField;

In Chrome I get:

Uncaught TypeError: Cannot read property 'data' of undefined(anonymous function) @ EmpStarter.html:981
progress.data.JSTableRef.foreach @ progress.all.4.0.min.js:18
progress.data.JSDO.foreach @ progress.all.4.0.min.js:18
onAfterFill @ EmpStarter.html:980
b.Callbacks.c @ jquery.min.js:3
b.Callbacks.p.fireWith @ jquery.min.js:3
b.extend.Deferred.b.each.i.(anonymous function) @ jquery.min.js:3
progress.data.JSDO._fillComplete @ progress.all.4.0.min.js:18
progress.data.JSDO.onReadyStateChangeGeneric @ progress.all.4.0.min.js:18

If I use the progress.js (not the min) from GitHub, I get:

Uncaught TypeError: Cannot read property 'Observable' of undefined
EmpStarter.html:928 Uncaught TypeError: undefined is not a function

This is in a function that ultimately calls the function above.

Thoughts?

Posted by Marian Edu on 15-Jul-2015 09:32

jsrecord.data[descField] if descField is a variable that holds the field name you want

Posted by egarcia on 15-Jul-2015 09:31

Hello,

Thank you for the additional information. This info explains the code in the first post.

What about referring to the variable using square brackets?

Example:

document.getElementById(descField).value = jsdo.jsrecord.data[ descField ]

All Replies

Posted by kevin_saunders on 14-Jul-2015 04:41

Realised where the error is: jsdo.jsrecord.data should be jsrecord.data

Unfortunately, that returns undefined. Any ideas as to why?

Posted by egarcia on 14-Jul-2015 06:36

Hello,

The foreach method loops through the records in the JSDO memory. Internally, this is maintained in an array, you can access it for debugging using jsdo.<tableRef>._data, you could also use jsdo.getData() using the API.

jsrecord.data undefined, could mean that even though the array has elements, the items are not valid.

Could you take a look at the output from _data?

BTW, to debug, use progress.all.js which combines several files .  You could also use progress.js but you would need to include the other files.

I hope this helps.

Posted by kevin_saunders on 14-Jul-2015 10:32

Thanks for the tip on using progress.all.js.

Output from _data:

[Object]0: Object SexCode: "M" SexDescription: "Male" _id: "1436887777049-1"

Which is what I am expecting.

Posted by kevin_saunders on 15-Jul-2015 09:23

Found out what the issue is - it doesn't like using a variable for the field that I am looking for. If I use the actual field name then it works just fine.

Any ideas on how to use a variable, as I need this function to be as generic as possible?

Posted by egarcia on 15-Jul-2015 09:31

Hello,

Thank you for the additional information. This info explains the code in the first post.

What about referring to the variable using square brackets?

Example:

document.getElementById(descField).value = jsdo.jsrecord.data[ descField ]

Posted by Marian Edu on 15-Jul-2015 09:32

jsrecord.data[descField] if descField is a variable that holds the field name you want

Posted by kevin_saunders on 15-Jul-2015 09:52

Thanks you both - that has indeed fixed the issue.

This thread is closed