hi
from the following code i have to call to get data from these 2 function in sequence once i get the lvcDefaultSite from getDefalutSite function I need to use lvcDefaultSite as an input for the getProductionLine.
now i cannot pass parameter from function getDefalutSite to getProductionLine
1. JSDO execute function asynchronously. so both function fire an event onAfterFill when data filled complete. So this will not happen in sequene.
2.JSDO will execute both function at the same time so i will never get value to pass to getProductionLine function.
Do anyone have an idea to solve this issue?
function getDefalutSite(domain) { // calling fill reads from the remote OE server var domainFilter = "icc_domain='" + domain + "'"; var outPromise = new Promise((resolve, reject) => { try { var serviceURI = "http://localhost:8810/stdData", jsdoSettings = { serviceURI: serviceURI, catalogURIs: serviceURI + "/static/stdDataService.json" }, jsdosession, jsdo, promise; // create a new session object jsdosession = new progress.data.JSDOSession(jsdoSettings); promise = jsdosession.login("", ""); promise.done(function(jsdosession, result, info){ jsdosession.addCatalog(jsdoSettings.catalogURIs) .done(function(jsdosession, result, details){ // create a JSDO jsdo = new progress.data.JSDO({ name: 'InvCtrl' }); //jsdo.subscribe('AfterFill', onAfterFillCustomers, this); // calling fill reads from the remote OE server jsdo.fill(domainFilter).done(onAfterFilliccCtrl); resolve('Done'); }) .fail(function(jsdosession, result, details){ alert("Error while executing addCatalog()."); }); }); promise.fail(function(jsdosession, result, info){ alert("Error while executing login()."); reject("Error while executing login()."); }); } catch (e) { alert("Error instantiating objects: " + e); reject("Error instantiating objects: " + e); } }); return outPromise; // this function is called after data is returned from the server function onAfterFilliccCtrl(jsdo, success, request) { // for each customer record returned jsdo.tticc_ctrl.foreach(function (icc) { // write out some of the customer data to the page console.log("icc_site = " + icc.data.icc_site); lvcDefaultSite = icc.data.icc_site; }); } } function getProductionLine(domain,site){ // calling fill reads from the remote OE server var domainFilter = "ln_domain='" + domain + "' and ln_site ='" + site + "'"; // this function is called after data is returned from the server function onAfterFillProductionLine(jsdo, success, request) { // for each customer record returned jsdo.ttln_mstr.foreach(function (prodLine) { // write out some of the customer data to the page console.log("ln_line=" + prodLine.data.ln_line ); lvcProdList.push(prodLine.data.ln_line); }); } try { var serviceURI = "http://localhost:8810/stdData", jsdoSettings = { serviceURI: serviceURI, catalogURIs: serviceURI + "/static/stdDataService.json" }, jsdosession, jsdo, promise; // create a new session object jsdosession = new progress.data.JSDOSession(jsdoSettings); promise = jsdosession.login("", ""); promise.done(function(jsdosession, result, info){ jsdosession.addCatalog(jsdoSettings.catalogURIs) .done(function(jsdosession, result, details){ // create a JSDO jsdo = new progress.data.JSDO({ name: 'LineMstr' }); //jsdo.subscribe('AfterFill', onAfterFillCustomers, this); // calling fill reads from the remote OE server jsdo.fill(domainFilter).done(onAfterFillProductionLine); }) .fail(function(jsdosession, result, details){ alert("Error while executing addCatalog()."); }); }); promise.fail(function(jsdosession, result, info){ alert("Error while executing login()."); }); } catch (error) { alert("Error instantiating objects: " + e); } }
Hello,
The simplest solution would be to call getProductionLine() from within onAfterFilliccCtrl().
You could also rearrange your code and chain the Promises.
The code that you posted shows both sessions being created for the service. You can just create one session for the given service. This would also simplify the code and make the solution clearer.
I hope this helps.
P.S.: Just in case you have not noticed it, there is a typo in getDefaultSite().
Hello,
The simplest solution would be to call getProductionLine() from within onAfterFilliccCtrl().
You could also rearrange your code and chain the Promises.
The code that you posted shows both sessions being created for the service. You can just create one session for the given service. This would also simplify the code and make the solution clearer.
I hope this helps.
P.S.: Just in case you have not noticed it, there is a typo in getDefaultSite().
it works thank you