I have realized that when I add a dataElement in a dataSet in the overwrite category setting it is left empty by default. The dataset will display this dataElement with its configured category combination (same and expected result as defining it to <No overwrite).
However, the response retrieved from api/dataSet/ shows the dataSetElement without the category field whereas when specifically setting it as it retrieves the DE category combo.
For instance, in the play server the dataset Child Health has all its DE category combos empty:
Thanks for your commitment, I’m well hope you also are. So the short answer is no, the long is yes,but …
To give more context: we are using some scripts that rely on extracting the DE categoryCombos from the dataSets endpoint. As we observed that those categoryCombos are not extracted if the dataSetElements (DSE) categorycombo is left blank, we set all those DE as < No override > instead and that works for us.
My question is purely related to the API component and would be rather: if the DSE categorycombo is not overwritten, should we be able to extract that property from the DSE or from the dataElements endpoint instead? In other words, what is the behavour we should expect from the API in this case: the one when categorycombo is blank in the UI or the one set as < No overwrite > ? (of course, giving the fact that they should not be discrepancies between them)
Hi facing a similar issue on 2.32, and I’m updating a certain dataset with 200 or so data elements. I’ve noticed this behaviour, and setting DE as < No override > solves the unusual behaviour. However doing this on the front end is a lot of work. How did you set all your DE as < No override >?
Well, rather than setting the DE as < No override >, for those dataset elements that had an undefined category combo, we created a little .js that put the same category combo as the one defined in the DE itself. Hope it helps:
const { config } = require("../config");
const { get_dataElement } = require("./library");
const { fetchJson, patchJson, putJson } = require("../api");
/**
* @module
* @description Script assign <No override> to the dataelement categoryCombo in datasets if not categoryCombo is assigned. Version 2.30
* @example <caption>Example usage of dataSets_override_categoryCombo</caption>
* //Run the script:
* node dataSets_override_categoryCombo.js
*
* @see https://hmisocba.msf.es
*/
const serverUrl = config.localUrl;
const queryDataSets = "dataSets?paging=false&fields=*&filter=id:eq:JlXoWZBjHAA";
(async function datasetElements() {
var updatedNeeded = false;
response = await fetchJson({ apiQuery: queryDataSets, url: serverUrl });
for (ds of response.dataSets) {
updatedNeeded = false;
for (dse of ds.dataSetElements) {
if (dse.categoryCombo == undefined) {
updatedNeeded = true;
de = await get_dataElement(dse.dataElement.id);
dse.categoryCombo = de.categoryCombo;
//console.log("________________________");
// console.log(dse);
}
}
if (updatedNeeded) {
console.log("___________UPDATED_______________");
console.log("DataSet: " + ds.name + " DataSet ID: " + ds.id);
const updateDataset = await putJson({ apiQuery: "dataSets/" + ds.id, url: serverUrl, body: ds });
}
}
})();
And the library
//Function Library
const { config } = require("../config");
const { fetchJson, postJson } = require("../api");
const _ = require("lodash");
const XLSX = require("xlsx");
/**
* @module
* @description Library of javascript functions
*
* @see https://hmisocba.msf.es
*
*/
/**
* Get a dataElement by the id
* @method get_dataElement
* @param {text} de_id - UID of the dataElement
* @return {json} DataElement
*/
async function get_dataElement(de_id, serverUrl) {
const de = await fetchJson({
url: serverUrl,
apiQuery: `dataElements/${de_id}?fields=*`
});
return de;
}