Hi,
OE 11.3.0 (still have to install 11.5 on this machine). The unsubscribe below does not work, so I made a workaround.
Is there something wrong with my call to unsubscribe?
dataModel.setData = function(ttName, pagingData) {
setDataCalls += 1;
if (typeof pagingData === "undefined") {
temptableName = ttName;
pagingData = [];
pagingData.push({PageNum:"1", RecordsPerPage:"20"}); // initially show page 1 with 20 records
}
var onAfterInvokeCustomRead = function (jsdo, success, request ) {
jsdo.unsubscribe('afterInvoke', onAfterInvokeCustomRead, jsdo);
var res = request.response;
if (success) {
res = res[Object.keys(res)[0]]; // SH Object.keys(res)[0] gets the first propertyname, it is the output parameter name (name of the dataset)
res = res[Object.keys(res)[0]];
res = (temptableName !== "") ? res[temptableName] : res[Object.keys(res)[0]]; // SH no temptableName set? then it must be the first
try{
jsdo.addRecords(res, progress.data.JSDO.MODE_EMPTY);
} catch(e) {
console.log("Error executing function in dataModel.setData: jsdo.addRecords, exception: " + e.message);
} console.log("onAfterInvokeCustomRead");
eventManager.fireEvent("set-data", function(listener){
listener.listenerFunction(res);
});
}
else {
if (res && res._errors &&
res._errors.length > 0){
var lenErrors = res._errors.length;
for (var idxError=0; idxError < lenErrors; idxError++) {
var errorEntry = res._errors[idxError];
var errorMsg = errorEntry._errorMsg;
var errorNum = errorEntry._errorNum;
/* handle error */
console.log("Error executing function onAfterInvokeCustomRead in dataModel.setData: " + errorMsg + ", messagenumber " + errorNum);
}
}
}
};
if (setDataCalls === 1) {jsdo.subscribe('afterInvoke', 'CustomRead', onAfterInvokeCustomRead);}
jsdo.CustomRead({ttReadOptions:{ttReadOptions:pagingData}});
}
--
Kind regards,
Stefan Houtzager
Houtzager ICT consultancy & development
Hello Stefan,
A couple of things:
- The progress.jsdo.js file is distributed as part of the Mobile App Builder and is not specific to a version of OpenEdge. This means that if you are using the Mobile App Builder, you should have access to progress.jsdo.3.1.js which is the latest version.
- It looks that the issue with unsubscribe is that the scope is not specified in when doing the subscribe. Internally, the code matches the the scope for the subscribe and the unsubscribe.
In this code, subscribe is not specifying a scope and unsubscribe is using "jsdo" as the scope.
jsdo.subscribe('afterInvoke', 'CustomRead', onAfterInvokeCustomRead)
jsdo.unsubscribe('afterInvoke', onAfterInvokeCustomRead, jsdo);
I hope this helps.
Thanks Edsel, allas changing the subscribe to
jsdo.subscribe('afterInvoke', 'CustomRead', onAfterInvokeCustomRead, jsdo);
does not help.
You are welcome, Stefan.
I will try to reproduce the issue later today.
I will let you know what I find.
Thanks.
Hello Stefan,
I was not able to reproduce the issue.
I tested subscribing/unsubscribing with a function definition, with a function inline in the subscribe call and with a variable pointing to the function as in your example.
I all cases, the unsubscribe method worked fine.
You can access my test program at the following URL:
oemobiledemo.progress.com/.../example004a.html
If you can share a reproducible case, I can take a look.
I hope this helps.
BTW, I am curious on why do you need to unsubscribe in your application?
If you always want to execute the code in the handler for AfterInvoke, then you do not need to unsubscribe.
Thanks.
Thanks Edsel,
datamodel.setdata is called each time a different page is selected. If I do not unsubscribe each timeone more event start to fire. If I can produce something testable for you I'll send it.
Btw the addrecords in my code was not ok, the temptablereference has to be added. Otherwise the _id field is not assigned. I can see that when I hardcode it, have to find out the dynamic functioncall tomorrow I hope.
Regards, Stefan.
Edsel, I saw yesterday at home that in your example it works ok. For my function I need the workaround. Allas it is not easy to create something testable for you, in the first place they only have an awfully outdated browser with internetconnection at my work. But as soon as I have the time I will work on something testable at home and send this to you when I can reproduce the problem. In the meantime I have a dynamic call for the addrecords, for those interested:
var funcName = dataModel.jsdoFnStart() + "addRecords"; // dataModel.jsdoFnStart() evals to
// jsdo.eCustomer.
eval(funcName+'(res, progress.data.JSDO.MODE_EMPTY)');
Regards, Stefan.
Hi Edsel,
I found the bug. For unsubscribe I used jsdo.unsubscribe('afterInvoke', onAfterInvokeCustomRead, jsdo);
In your first response (19 Feb 2015 12:02) you did not notice this, but in your sample you use an extra parameter:
jsdo.unsubscribe('AfterInvoke', 'CustomRead', onAfterInvokeCustomReadInline, jsdo);
I added it and the problem is gone. Thanks for your help again!
FYI: the code sent first was incomplete as dataModel can reference different dataModel objects. So I have a dataModel.jsdo (and more) now.
--
Kind regards,
Stefan Houtzager
Houtzager ICT consultancy & development
www.linkedin.com/in/stefanhoutzager
Hello Stefan,
Great.
I am glad that you found the difference between the statements.
I will check to see if we can add a validation to avoid this type of issues.
Thank you and regards.