Scripts in Custom Form not running in Dataset report mode

I have some custom Forms with Scripts to perform a variety of summaries which takes time to achieve with indicators. These scripts are not working in Dataset mode.

Is there something that I have to do to be able to run them in Dataset mode?

Thanks

Hi @dmaritim,

What kind of problem are you having? Share a little detail. You can check the below example to call any api inside data entry form or can do any calculation:

dhis2.util.on( 'dhis2.de.event.formReady', function( event, aLpVgfXiz0f) {

var orgName= $( '#selectedOrganisationUnit' ).val();// From DHIS2 Selection Param
jQuery.get("https://play.dhis2.org/2.31dev/api/organisationUnits.json?query="+orgName+"&fields=id,level",function(jsonResponse){
	$.each(jsonResponse, function(key, value){
		var arr = [];
		for(var info in value){
		  arr.push(value[info]);
		}
		var level =value[info]['level'];
		if(typeof level != 'undefined'){
		 console.log({level});
		}
   });
  });
});

 

You can find more custom scripts here: http://dhis2trainingland.com/eportal/

Thanks
Julhas

@julhas
All my Scripts are working perfectly in the Dataentry Module. The summaries are done accurately, however, in the Dataset report mode, those summaries disappear even the console.log() outputs. It is like those scripts done run at all.

Check example below:

dhis2.util.on(dhis2.de.event.dataValuesLoaded, function(event, ds) {
console.log(“DataValueLoaded function runned”);
myfunction.loadWithDelay();
});

Hi all,

My investigation has taken me through various Scripts in DHIS2. Of interest is the dataSetReport.js especially towards the end where you have the below script. What does this mean?
/------------------------------------------------------------------------------
// Hooks in custom forms - must be present to avoid errors in forms
//------------------------------------------------------------------------------

function onValueSave( fn )
{
// Do nothing
}

function onFormLoad( fn )
{
// Do nothing
}

Need help.

Hi Members,

Still looking for help in ensuring that JQuery scripts for dhis2.de.event.dataValuesLoaded are running when a dataset is open in dataset report module.

Are there known issues that prevent this event from running in dataet report module?

Your help is highly appreciated.

Hi @julhas , @dmaritim

I do not have any experience with javaScript or jQuery.

I want to prevent a data entry clerk from entering data for some data elements if the answer to the previous data element is NO. Below is a part of the custom form I have designed. It’s a data set.

I would like the code to be embedded in the Html source code of the custom form, so any step by step guidance will be helpful.

Thanks

Hi @ferdinandmussavene,

You can add your custom JS as I mentioned on the above comment.

dhis2.util.on( ‘dhis2.de.event.formReady’, function( event, aLpVgfXiz0f) {

var orgName= $( ‘#selectedOrganisationUnit’ ).val();// From DHIS2 Selection Param
jQuery.get(“https://play.dhis2.org/2.31dev/api/organisationUnits.json?query="+orgName+"&fields=id,level”,function(jsonResponse){
$.each(jsonResponse, function(key, value){
var arr = [];
for(var info in value){
arr.push(value[info]);
}
var level =value[info][‘level’];
if(typeof level != ‘undefined’){
console.log({level});
}
});
});
});

You can find more scripts here: http://dhis2trainingland.com/eportal/?tutorial=linking-dhis2-to-an-external-web-portal-using-dhis2-web-api

http://dhis2trainingland.com/eportal/?tutorial=how-to-calculate-previous-month-value-in-dhis2-data-entry-form

Find a few more posts on the custom JS here: http://dhis2trainingland.com/eportal/

If you need anymore support don’t hesitate to let me know.

Regards
Julhas

Hi @julhas,

In the HTML code of the custom form, For each data element, we have ID, TITLE and Value. How do these fit in the Script? This is one of my problem. Also, in the script I see two variables: arr which is any array and level. I was wondering if you could comment each line of the code to help me understand it.

Thanks in advance.