[progress Communities] [progress Openedge Abl] Forum Post: Re: [4.2] - Multiple Selectquery...

Status
Not open for further replies.
M

Mohammed Siraj

Guest
Iram, you can consider using JavaScript Promise concept for asynchronous computation. In the example below, will be using jQuery library Deferred & Promise objects to ensure cross browser support. var deferredInstance = $.Deferred(); var allContacts = {}; //map of all contacts by account id rbf_selectQuery2('SELECT id from account where name like %google%', function accounts_callback(values) { for (var i = 0; i < values.length; i++) { rbf_selectQuery2('SELECT name, id, firstName, lastName FROM contact where accountId = ' + values[0], function contact_callback(values2) { for (var j = 0; j < values2.length; j++) { // get contact information var accountId = String(values[0]); allContacts[accountId] = {}; allContacts[accountId].name = values2[j][0]; allContacts[accountId].id = values2[j][1]; } deferredInstance.resolve(allContacts); }); } }); deferredInstance.done(processContacts); function processContacts(){ // After all the accounts are done and all the contacts are done, then I want this code to run //process allContacts... } Eventhough JavaScript closure concept will let you nest functions and provide access to outer function scope, avoid nesting greater than two levels and leverage Deferred/Promise objects for asynchronous computation. Hope this helps.

Continue reading...
 
Status
Not open for further replies.
Top