dsCustomer.subscribe('afterInvoke', 'GetCreditInfo',
onAfterInvokeGetCreditInfo); var currentCust = { piCustNum : 10 }; dsCustomer.GetCreditInfo ( currentCust ); function onAfterInvokeGetCreditInfo (jsdo , success , request ) { /* check for errors on this Invoke operation */ if (success) { /* do the normal thing for a successful Invoke operation. */ /* for example, evaluate the CreditLimit for Customer currentCust and if their Balance is greater, display a message . . . */ if (request.response._retVal && request.response._retVal < 1000.00) { var poCustomer = request.response.poCustomer.poCustomer; if (dsCustomer.find(function(jsrecord) { return (jsrecord.data.CustNum == poCustomer[0].data.CustNum); }) { if (dsCustomer.Balance > request.response._retVal) { console.log("Customer " + dsCustomer.CustNum + " " + dsCustomer.Name + " has a Balance higher than their CreditLimit" ); } } } } else { /* return errors from this Invoke operation */ if (request.response && request.response._errors && request.response._errors.length > 0){ var lenErrors = request.response._errors.length; for (var idxError=0; idxError < lenErrors; idxError++) { var errorEntry = request.response._errors[idxError]; var errorMsg = errorEntry._errorMsg; var errorNum = errorEntry._errorNum; /* handle Invoke operation error . . . */ } } } }; |
var currentCust = { piCustNum : 10 };
dsCustomer.invoke ( "GetCreditInfo", currentCust ).done( function( jsdo, success, request ) { /* do the normal thing for a successful Invoke operation. */ /* for example, evaluate the CreditLimit for Customer currentCust and if their Balance is greater, display a message . . . */ if (request.response._retVal && request.response._retVal < 1000.00) { var poCustomer = request.response.poCustomer.poCustomer; if (dsCustomer.find(function(jsrecord) { return (jsrecord.data.CustNum == poCustomer[0].data.CustNum); }) { if (dsCustomer.Balance > request.response._retVal) { console.log("Customer " + dsCustomer.CustNum + " " + dsCustomer.Name + " has a Balance higher than their CreditLimit" ); } } } }).fail( function( jsdo, success, request ) { /* return errors from this Invoke operation */ if (request.response && request.response._errors && request.response._errors.length > 0) { var lenErrors = request.response._errors.length; for (var idxError=0; idxError < lenErrors; idxError++) { var errorEntry = request.response._errors[idxError]; var errorMsg = errorEntry._errorMsg; var errorNum = errorEntry._errorNum; /* handle Invoke operation error . . . */ } } }); |
var currentCust = { piCustNum : 10 };
var request = null; try { request = dsCustomer.GetCreditInfo ( currentCust, false )); if (!request.success) { throw "Invoke request to GetCreditInfo() not successful for CustNum == " + "for CustNum == " + currentCust.piCustNum.toString(); } /* do the normal thing for a successful Invoke operation. */ /* for example, evaluate the CreditLimit for Customer currentCust and if their Balance is greater, display a message . . . */ else if (request.response._retVal && request.response._retVal < 1000.00) { var poCustomer = request.response.poCustomer.poCustomer; if (dsCustomer.find(function(jsrecord) { return (jsrecord.data.CustNum == poCustomer[0].data.CustNum); }) { if (dsCustomer.Balance > request.response._retVal) { console.log("Customer " + dsCustomer.CustNum + " " + dsCustomer.Name + " has a Balance higher than their CreditLimit" ); } } else { /* No such record in dsCustomer */ throw "No dsCustomer record with CustNum == " + currentCust.piCustNum.toString(); } } else { throw "dsCustomer.GetCreditInfo() returns " + "out-of-range CreditLimit for CustNum == " + currentCust.piCustNum.toString(); } } catch(err) { /* handle error with access to request . . . */ }; |