jsrecord not returning field

Posted by mflanegan on 13-Jan-2016 04:17

Hi there, 

I am currently trying to access an individual field from from the dataset file that was returned by the appserver. 

The following is an example from my code:

var dataSet = new progress.data.JSDO('beLogin');
dataSet.fill(btoa(userfilter),"").done
(
function(jsdo, success, request)
{
jsdo.foreach( function(jsrecord)
{
console.log("username: " + JSON.stringify(jsrecord.data.username));
});
console.log("Login Success!");
})

Each time this is run, it returns undefined. 

If i just message out:

console.log("username: " + JSON.stringify(jsrecord.data));

The full dataset is returned, consisting of the temp table and all its fields.

How can I access a specific field?

Thanks in advance.

All Replies

Posted by egarcia on 13-Jan-2016 05:39

Hello,

You should be able to access a specific field in the way you are doing: jsrecord.data.username.

See a working example at: oemobiledemo.progress.com/.../example013.html

The value of jsrecord.data should be just the record and not the full dataset nor the temp-table.

It looks like in your environment somehow the response from the server is not expected, it does not match what the catalog specifies for the resource.

Make sure that the READ method in the Business Entity is returning a DataSet and not a temp-table.

You could compare the structure of the catalog and the payload of the HTTP response in your code with the one in the example to see where the structure differ.

Also, I noticed that you are passing two parameters to the fill() method. It only expects one parameter.

I hope this helps.

Posted by mflanegan on 13-Jan-2016 07:00

Hi Edsel,

We are definitely sending back a dataset, we have also replaced our code with that of your demos.

We still have the same problem. we get this error, Uncaught TypeError: Cannot read property 'foreach' of undefined, in the after row fill.

here is our code below:

               function onAfterFillCustomers(jsdo, success, request) {

                        /*dataset*/                 /*temp-table*/

                   jsdo.dssysuser.foreach(function (ttsysuser) {

                       console.log("username: " + ttsysuser.data.username);

                   });

               }

               var serviceURI = "http:.....",

                   catalogURI = serviceURI + "......",        

                   jsdosession, jsdo;

               jsdosession = new progress.data.JSDOSession({

                   serviceURI: serviceURI,

                   catalogURIs: catalogURI

               });

               jsdosession.login("", "").done(function(jsdosession, result, info) {

                    jsdosession.addCatalog(catalogURI)

                       .done(function(jsdosession, result, details) {

                                                                                                    /*business entity*/                  

                           jsdo = new progress.data.JSDO({ name: 'beLogin' });

                           jsdo.fill(btoa(userfilter)).done(onAfterFillCustomers);

                       });

               });

we can see the below returned from the fill in the developer tools (chrome) debugger:

{"dssysuser":{"ttsysuser":[{"ttcrstop":"","ttlimit":"   1155063.02 ","ttmsg":"","ttmaster":"","username":"prg50","userco":"50","useraccno":"50122924","note":"true"}]},"_id":"1452689130499-1"}

The only difference between the appserver and this, is the fact that there is an _id added to the end of the dataset returned. Otherwise all fields and datasets and temp-tables  match 100%. We are still unable to access a field in our dataset.

Posted by egarcia on 14-Jan-2016 04:31

Hello Meyrick,

The syntax for the foreach() should be jsdo.foreach() if you have only one table in the DataSet or jsdo.ttsysuser.foreach() where you explicitly name the table reference. Please try it this way.

Why is _id at the same level as the DataSet property? I would expect _id to be at the record level but no at the top level. Is it some sort of caching?

I wonder if this is what is causing the issue. Could you try without it to see the behavior?

Thanks.

This thread is closed