_id: How to operate on Temp-Tables repsonse in INVOKE (vs th

Posted by Roger Blanchard on 18-Jun-2014 08:02

When using a read operation there is an _id field that gets created automatically. This can be used to find a record locally and update/delete it. When creating our own INVOKE operations that return a TT this _id is not created automatically. Can we add this ourselves as to allow for local db updates on mobile device?

All Replies

Posted by egarcia on 18-Jun-2014 08:39

The READ operation updates the records in the JSDO memory.

The INVOKE operation returns the TT but its data is not in the JSDO.

You can work with the JavaScript object returned by the INVOKE directly.

Alternatively, you can use the addRecords() method.

Example:

jsdo.eCustomer.addRecords(request.response.dsCustomer, progress.data.JSDO.MODE_EMPTY);

You can see a sample program using addRecords() at the following URL:

http://oemobiledemo.progress.com/jsdo/example006.html

Here is the source code:

<!DOCTYPE html>
<html>
<head>
    <script src="http://oemobiledemo.progress.com/jsdo/progress.session.js"></script>
    <script src="http://oemobiledemo.progress.com/jsdo/progress.js"></script>
    <script>
        var serviceURI = "http://oemobiledemo.progress.com/MobilityDemoService"; 
        var catalogURI = "http://oemobiledemo.progress.com/MobilityDemoService/static/mobile/MobilityDemoService.json";

        session = new progress.data.Session();
        session.login(serviceURI, "", "");
        session.addCatalog(catalogURI);

        jsdo = new progress.data.JSDO({ name: 'dsCustomer' });
        //jsdo.subscribe('AfterFill', onAfterFillCustomers, this);    
        //jsdo.fill();

		jsdo.subscribe('AfterInvoke', 'CustomRead', onAfterInvokeCustomRead, this); 
        jsdo.CustomRead({});

        function onAfterFillCustomers(jsdo, success, request) {
            jsdo.eCustomer.foreach(function(customer) {
				console.log(jsdo.eCustomer.getId() + " " + customer.data._id);
                document.write(customer.data.CustNum + ' ' + customer.data.Name + '<br>');
            }); 
        }
		
        function onAfterInvokeCustomRead(jsdo, success, request) {		
			jsdo.eCustomer.addRecords(request.response.dsCustomer, progress.data.JSDO.MODE_EMPTY);
		
            jsdo.eCustomer.foreach(function(customer) {
				console.log(jsdo.eCustomer.getId() + " " + customer.data._id);
                document.write(customer.data.CustNum + ' ' + customer.data.Name + '<br>');
            }); 
        }
    </script>
</head>
<body>
</body>
</html>

I hope this helps.

Posted by Roger Blanchard on 18-Jun-2014 08:53

this does help...thanks.

This thread is closed