Dear Jeam,
Thanks for your suggestion.
I used the script that you send me and I tried it but i got an error (see debug2.JPG) that the object does not support property or method "set values". I changed it also as you can see below to get the promptName, using configuration but I still got the same error. I performed debugging and I found that prompt object was not recognized (see debug2.JPG).
I'm also attaching the sample report (Report.txt) that I used to perform the test which is based on Great outdoors data module.
I will appreciate any suggestion for the cause of this error.
define(
function()
{
"use strict";
function SetValuePrompt() {
};
SetValuePrompt.prototype.draw = function(oControlHost)
{
var o = oControlHost.configuration;
this.ctrlFrom = o["promptName"];
var oDataStore = oControlHost.control.dataStores[0];
var iRowCount = oDataStore.rowCount;
var sValue = [];
for (var i = 0; i < iRowCount; i++) {
sValue.push({ "use": oDataStore.getCellValue(i, 0) });
}
this.ctrlFrom.setValues(sValue);
oControlHost.valueChanged();
if(!o["submit"]) oControlHost.next();
};
return SetValuePrompt;
}
);
Kind Regards,
Pantelis Stavroulidakis
------------------------------
Pantelis Stavroulidakis
------------------------------
Original Message:
Sent: Wed November 03, 2021 03:45 PM
From: JEAM COELHO
Subject: Set dynamically (e.g. using javascript) default selections in a multi-select prompt
Hi,
It's is pretty easy using Custom Controls.
Take a look at https://community.ibm.com/community/user/businessanalytics/blogs/steven-macko/2018/09/10/javascript-samples-for-ibm-cognos-analytics
I wrote this code and add a custom control in report that references js file.
This control catches item values added to custom control data store and make then selected in the prompt.
define(function() { "use strict"; function SetValuePrompt() {}; SetValuePrompt.prototype.draw = function(oControlHost) { var o = oControlHost.configuration; var oDataStore = oControlHost.control.dataStores[0]; var iRowCount = oDataStore.rowCount; var sValue = []; for (var i = 0; i < iRowCount; i++) { sValue.push({ "use": oDataStore.getCellValue(i, 0) }); } oControlHost.page.getControlByName(o["promptName"]).setValues(sValue); oControlHost.valueChanged(); if(!o["submit"]) oControlHost.next(); }; return SetValuePrompt;});
------------------------------
JEAM COELHO
Cognos Solution Architect
LinkedIn: https://www.linkedin.com/in/jeamcoelho/
------------------------------