Cognos 11.0.11 - Javascript显示/隐藏日期提示

时间:2018-06-07 09:59:01

标签: javascript cognos

我在一段时间后从网站上获得了以下javascript,根据单选按钮值提示中的选项显示并隐藏了日期提示。

<script type="text/javascript">
var inputs = document.getElementsByTagName("input");
var list_box = new Array();

/****Identify Radio Buttons and load them into an array****/
var radio_buttons = new Array();
j=0;

for(i=0;i<inputs.length;i++)
{
if(inputs[i].type=='radio')
  {
    radio_buttons[j] = inputs[i];
    j++;
  }   
}

/****Set the onclick event of each radio button option to trigger our custom function****/
radio_buttons[0].setAttribute("onclick",function(){ToggleDate();});
radio_buttons[1].setAttribute("onclick",function(){ToggleDate();});
radio_buttons[2].setAttribute("onclick",function(){ToggleDate();});


/****Create a handle for date prompt****/
var prompt = document.getElementById("date_prompts").childNodes[0];

function ToggleDate()
{
if(radio_buttons[0].checked)
  {
  /**** First options (in our case "Custom") is selected.**** 
   **** Date Prompt will be Shown or Enabled.            ****/

  document.getElementById("date_prompts").style.display = '';  //show
  // prompt.disabled = '';   //enable

  canSubmitPrompt();
  }
else
  {
  /**** Second options (in our case "Yesterday") is selected.****
   **** Date Prompt will be Hidden or Disabled.              ****/

  document.getElementById("date_prompts").style.display = 'none';   //hide
  //prompt.disabled = 'true';   //disable

  canSubmitPrompt();
  }
}
</script> 

虽然我们一直在使用Cognos 10.2.2,但这段代码运行良好(与其他几个跨越日期提示的html项目一起使用)。我们现在正在升级到Cognos 11.0.11,而我已在新环境中测试报告,我发现此代码不再有效,并且显示日期提示使用单选按钮选择了哪些选项。

请有人可以给我一些指示,告诉我这里可能会发生什么,或者更好地告诉我如何解决这个问题。

在Cognos 11中创建新报表并单独添加元素时,会出现以下错误消息...

HTML报告输出格式不正确。如果您的报告使用&#34; HTML项目&#34;元素确保它们产生格式良好的HTML。

原因:名称包含无效字符。

URL: 行:274 性格:24 资源: 对于(I = 0;我

2 个答案:

答案 0 :(得分:1)

Cognos使用Cognos 10.2发布了一个JavaScript API,极大地简化了您在此处所做的工作。此外,它保证在版本之间得到支持。

以下是针对Cognos JavaScript API编写的相同功能:

假设:

  • 将单个Cognos Select提示配置为单选按钮组,其名称属性“radio_buttons”可选择三个单独的值(1,2和3)
  • 包含id属性'date_prompts'的范围中的日期提示应该在选择第一个单选按钮时显示,但如果选择了其他两个单选按钮则不显示

<强>代码

var report = cognos.Report.getReport('_THIS_'); //Get report reference
var radioprompt = report.prompt.getControlByName('radio_buttons'); //Get prompt reference
var datespan = document.getElementById('date_prompts'); //Get span to hide/unhide

radioprompt.setValidator(validateRadio); //Assign a validation function

function validateRadio(values) {
     var result = true;
     if (values && values.length > 0) { //Make sure prompt has value
          if (values[0].use == '1') {  //Check if first radio button selected
               datespan.style.display = ''; //Show
          } else {
               datespan.style.display = 'none'; //Hide
          }
     }    
     return result; //Return result to Cognos. Always true in this case.
}

您可以在此处找到有关Cognos JavaScript API的更多信息:Cognos 11 JavaScript API Documentation

答案 1 :(得分:0)

你可以用渲染变量来做到这一点。

  1. 将报告的以完全互动属性设置为
  2. 创建提示页面并添加值提示和日期提示。
  3. 将值提示的选择UI 属性设置为单选按钮组
  4. 将值提示的自动提交属性设置为
  5. 将值显示日期提示隐藏日期提示添加到值提示的静态选项属性中。
  6. 创建一个字符串变量(Queries | Condition explorer),它使用与值提示相关联的参数。
  7. 将日期提示的渲染变量属性设置为上一步中创建的变量。取消选择隐藏日期提示
  8. 要使自动提交功能无法运行报告,您可能需要创建一些自定义功能来替换完成按钮。请参阅下面的报告规范中的示例代码。 (以完全交互方式运行属性似乎不会存储在报告规范中。您需要手动设置。)

    此特定示例在兼容模式下以10.2.1或11.0.7工作(以完全交互运行=否)。我还没有使用RequireJS在11.0.4+中正确地做到这一点。

    <report xmlns="http://developer.cognos.com/schemas/report/14.1/" useStyleVersion="11.4" expressionLocale="en-us">
        <drillBehavior/>
        <layouts>
            <layout>
                <reportPages>
                    <page name="Page1">
                        <style>
                            <defaultStyles>
                                <defaultStyle refStyle="pg"/>
                            </defaultStyles>
                        </style>
                        <pageBody>
                            <style>
                                <defaultStyles>
                                    <defaultStyle refStyle="pb"/>
                                </defaultStyles>
                            </style>
                            <contents/>
                        </pageBody>
                    </page>
                </reportPages>
                <promptPages>
                    <page name="Prompt page1">
                        <pageHeader>
                            <contents>
                                <block>
                                    <contents>
                                        <textItem>
                                            <dataSource>
                                                <staticValue>Prompt Page</staticValue>
                                            </dataSource>
                                            <style>
                                                <defaultStyles>
                                                    <defaultStyle refStyle="tt"/>
                                                </defaultStyles>
                                            </style>
                                        </textItem>
                                    </contents>
                                    <style>
                                        <defaultStyles>
                                            <defaultStyle refStyle="ta"/>
                                        </defaultStyles>
                                    </style>
                                </block>
                            </contents>
                            <style>
                                <defaultStyles>
                                    <defaultStyle refStyle="hp"/>
                                </defaultStyles>
                            </style>
                        </pageHeader>
                        <pageBody>
                            <contents>
                                <table>
                                    <style>
                                        <defaultStyles>
                                            <defaultStyle refStyle="tb"/>
                                        </defaultStyles>
                                        <CSS value="border-collapse:collapse;width:100%"/>
                                    </style>
                                    <tableRows>
                                        <tableRow>
                                            <tableCells>
                                                <tableCell>
                                                    <contents>
                                                        <selectValue selectValueUI="radioGroup" autoSubmit="true" parameter="ShowHide">
                                                            <selectOptions>
                                                                <selectOption useValue="Show Date Prompt">
                                                                    <displayValue>Show Date Prompt</displayValue>
                                                                </selectOption>
                                                                <selectOption useValue="Hide Date Prompt">
                                                                    <displayValue>Hide Date Prompt</displayValue>
                                                                </selectOption>
                                                            </selectOptions>
                                                        </selectValue>
                                                        <selectValue parameter="Parameter2" cascadeOn="ShowHide" required="false">
                                                            <style>
                                                                <CSS value="visibility:hidden"/>
                                                            </style>
                                                        </selectValue>
                                                    </contents>
                                                    <style>
                                                        <CSS value="text-align:left;vertical-align:top"/>
                                                    </style>
                                                </tableCell>
                                                <tableCell>
                                                    <contents>
                                                        <selectDate parameter="Date">
                                                            <conditionalRender refVariable="String1">
                                                                <renderFor refVariableValue="Show Date Prompt"/>
                                                            </conditionalRender>
                                                        </selectDate>
                                                    </contents>
                                                    <style>
                                                        <CSS value="text-align:left;vertical-align:top"/>
                                                    </style>
                                                </tableCell>
                                            </tableCells>
                                        </tableRow>
                                    </tableRows>
                                </table>
                            </contents>
                            <style>
                                <defaultStyles>
                                    <defaultStyle refStyle="py"/>
                                </defaultStyles>
                            </style>
                        </pageBody>
                        <pageFooter>
                            <contents>
                                <promptButton type="cancel">
                                    <contents/>
                                    <style>
                                        <defaultStyles>
                                            <defaultStyle refStyle="bp"/>
                                        </defaultStyles>
                                    </style>
                                </promptButton>
                                <promptButton type="finish">
                                    <contents/>
                                    <style>
                                        <defaultStyles>
                                            <defaultStyle refStyle="bp"/>
                                        </defaultStyles>
                                    </style>
                                </promptButton>
                            </contents>
                            <style>
                                <defaultStyles>
                                    <defaultStyle refStyle="fp"/>
                                </defaultStyles>
                            </style>
                        </pageFooter>
                        <style>
                            <defaultStyles>
                                <defaultStyle refStyle="pp"/>
                            </defaultStyles>
                        </style>
                    </page>
                </promptPages>
            </layout>
        </layouts>
        <XMLAttributes>
            <XMLAttribute output="no" name="RS_CreateExtendedDataItems" value="true"/>
            <XMLAttribute output="no" name="RS_modelModificationTime" value="2013-01-08T15:30:33.117Z"/>
            <XMLAttribute output="no" name="listSeparator" value=","/>
        </XMLAttributes>
        <modelPath>/content/folder[@name=&apos;Samples&apos;]/folder[@name=&apos;Models&apos;]/package[@name=&apos;GO Sales (query)&apos;]/model[@name=&apos;model&apos;]</modelPath>
        <reportVariables>
            <reportVariable type="string" name="String1">
                <reportExpression>ParamDisplayValue(&apos;ShowHide&apos;)</reportExpression>
                <variableValues>
                    <variableValue value="Show Date Prompt"/>
                    <variableValue value="Hide Date Prompt"/>
                </variableValues>
            </reportVariable>
        </reportVariables>
        <reportName>ShowHide</reportName>
    </report>