JSDO Find() method

Posted by Matheus R. Mokwa on 19-Feb-2016 12:59

I'm trying to retrieve a record from the server, using the find method.

In the documentation we got this code as example

var jsdo = new progress.data.JSDO( 'customer' );

jsdo.find(function(jsrecord) {
  return (jsrecord.data.CustNum == 10);
});

But for me this is very confusing, what should i do to grab the record from this point and/or execute the function? 

All Replies

Posted by egarcia on 19-Feb-2016 13:31

Hello,

For the code that you pasted you would need to call fill() prior to calling find().

find() works out of the local memory and expects a function that returns true/false to indicate that a record is found.

Here is a longer explanation.

The JSDO API is not quite like the ABL where the FIND statement reads from the server.

For the JSDO, only three methods interact with the server:

- fill() (same as read())

- saveChanges()

- invoke() (same as calling methods using the name)

The other methods in the JSDO, add()/create(), assign()/update(), remove(), find(), foreach() and others are entirely client-side and use the records in the local memory (or add to it).

The approach to handling the records is that you would call fill() to retrieve the records from the server into the local memory (JSDO memory) then use methods such as find() or foreach() which operate on the local memory.

See the following example where fill() is called using a where clause and then foreach() is used to read the records from the JSDO memory. You can use find() if you need to find just one record.

Example:

   oemobiledemo.progress.com/.../example013.html

Take a look at the network payload with the web inspector in the web browser.

Depending on your needs, you might also want to use paging.

There are some suggestions on this in the following thread:

   community.progress.com/.../23201

When using Kendo UI, you have the option of using the Kendo UI DataSource as your interface to the records.

You can use read() and then filter().

Please let me know if you need more information.

I hope this help.

Posted by maura on 19-Feb-2016 13:32

The find fn returns a reference to the record found, else null, and the record found becomes the working record for that table, so you could do the following:

jsdo.find(function(jsrecord) {

return (jsrecord.data.CustNum == 2100);

});

if (jsdo.record) {

   jsdo.record.remove();

}

Detailed doc below:

documentation.progress.com/.../

Posted by Matheus R. Mokwa on 19-Feb-2016 13:49

Awesome, thank you both.

This thread is closed