COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: dougp on 05 Nov 2018 04:22:43 PM

Title: JavaScript: Iterate through all of the prompts on a prompt page
Post by: dougp on 05 Nov 2018 04:22:43 PM
I want to iterate through all of the prompts on a prompt page, but I don't know how.

The documentation for the Prompt API in Cognos 10.2.2 shows a getControls() method.
https://www.ibm.com/support/knowledgecenter/en/SSEP7J_10.2.2/com.ibm.swg.ba.cognos.ug_cr_rptstd.10.2.2.doc/r_prmpt_api_cognos_prompt_getControls.html#cognos.prompt.getControls
So, in the compatible viewer, this is easy.

Looking at the documentation for the "new way" to do JavaScript in Cognos, I don't see a way to do this in the interactive viewer.  Am I just missing it, or is this feature gone?
Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: Boksberger on 05 Nov 2018 04:48:32 PM
Can you clarify 'iterate through'?

Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: CognosPaul on 05 Nov 2018 05:39:37 PM
The JS is similar to the non-interactive version:

oControlHost.page.getAllPromptControls()

It returns an array of prompts, on each one you can do the following protos:
autoSubmit
element
name
parameter

setValues
addValues
getValues
clearValues
setValidator

get/set/toggleDisplay
get/setVisible
toggleVisibility

Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: dougp on 06 Nov 2018 10:45:03 AM
Good find!
I don't see it in the documentation.  Does newer documentation describe the getAllPromptControls() method?  Or is this an Easter egg?
Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: CognosPaul on 07 Nov 2018 08:34:26 AM
I think this might be an easter egg. I'm not finding it in the documentation either. (documentation can be found here: https://www.ibm.com/communities/analytics/cognos-analytics-blog/javascript-support-in-interactive-viewer/ (https://www.ibm.com/communities/analytics/cognos-analytics-blog/javascript-support-in-interactive-viewer/)).

The autosubmit method is also new. I'm hoping this is the start of more of the original methods being exposed. The old API had dozens of really great functions that haven't been replicated yet.
Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: Boksberger on 08 Nov 2018 09:00:23 AM
IBM released new JS documentation for 11.0.10 and put it online: https://public.dhe.ibm.com/software/data/sw-library/cognos/mobile/scriptable_reports/index.html

If you want the zip, it is hosted here: https://www-01.ibm.com/support/docview.wss?uid=swg21990557

getAllPromptControls() is listed as a method for the Page interface.
Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: CognosPaul on 08 Nov 2018 09:05:03 AM
I was looking for that, thanks for finding the updated version!
Title: Re: JavaScript: Iterate through all of the prompts on a prompt page
Post by: dougp on 08 Nov 2018 05:36:32 PM
That's great!  Thanks.