Tracker capture(v26), services.js trying to read object as a array

Hi devs,

We are currently experiencing an issue in tracker capture (v26) registration process. When we do a new registration, it actually does necessary api calls to persist the registration, but front-end web application stops execution(doesn’t show feedback) due to a javascript exception which throws due to reading an object as an array.

Issue it at line line 1903 services.js branch v26,

1902 : var periods = getEventDuePeriod(null, stage, enrollment);

1903 : newEvent.dueDate = DateUtils.formatFromUserToApi(periods[0].endDate);

However, at line 1826 of services.js in branch v26,

it does following transformation after doing same method call(getEventDuePeriod) which returns an object,

var prds = getEventDuePeriod(eventsPerStage, programStage, enrollment);

var periods = prds && prds.availablePeriods && prds.availablePeriods.length ? prds.availablePeriods : [];

And does periods.length>0 check before accessing periods[0]. So I believe, same should be done at 1903.

I think this issue was not there in v25, since getEventDuePeriod() was actually returning an array.

​Please find a screenshot taken during the javascript debug attached with this email for further clarification.

Kindly let us know if this is an issue in code(services.js), or if this is an issue in our setup. If you can confirm this is a bug, I can send a PR with the fix.

Thanks & Regards,

Chathura

Selection_016.bmp (705 KB)

···

Best Regards,

Chathura Widanage,

Undergraduate,

Department of Computer Science and Engineering,

University of Moratuwa,

Sri Lanka

Hi there Chatura!

Thank you for the detailed report.

···

Please go ahead and send a PR, and I’ll test and merge.

Markus

Den 8. jul. 2017 kl. 08.54 skrev chathura widanage chathurawidanage@gmail.com:

Hi devs,

We are currently experiencing an issue in tracker capture (v26) registration process. When we do a new registration, it actually does necessary api calls to persist the registration, but front-end web application stops execution(doesn’t show feedback) due to a javascript exception which throws due to reading an object as an array.

Issue it at line line 1903 services.js branch v26,

1902 : var periods = getEventDuePeriod(null, stage, enrollment);

1903 : newEvent.dueDate = DateUtils.formatFromUserToApi(periods[0].endDate);

However, at line 1826 of services.js in branch v26,

it does following transformation after doing same method call(getEventDuePeriod) which returns an object,

var prds = getEventDuePeriod(eventsPerStage, programStage, enrollment);

var periods = prds && prds.availablePeriods && prds.availablePeriods.length ? prds.availablePeriods : [];

And does periods.length>0 check before accessing periods[0]. So I believe, same should be done at 1903.

I think this issue was not there in v25, since getEventDuePeriod() was actually returning an array.

​Please find a screenshot taken during the javascript debug attached with this email for further clarification.

Kindly let us know if this is an issue in code(services.js), or if this is an issue in our setup. If you can confirm this is a bug, I can send a PR with the fix.

Thanks & Regards,

Chathura


Best Regards,

Chathura Widanage,

Undergraduate,

Department of Computer Science and Engineering,

University of Moratuwa,

Sri Lanka

<Selection_016.bmp>


Mailing list: https://launchpad.net/~dhis2-devs
Post to : dhis2-devs@lists.launchpad.net
Unsubscribe : https://launchpad.net/~dhis2-devs
More help : https://help.launchpad.net/ListHelp