Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReportNet : 2 prompts 1

Status
Not open for further replies.

Draoued

MIS
Aug 1, 2002
378
FI
I have a requirement to have a report with 2 prompts but only one of them should be answered.
Do you know how I can make sure that at least one is mandatory ?
If I mark both of them as "required" then I need to answer both of them.
If I mark both of them as "optional" , it works , but user can skip both of them as well.

Any ideas ?
 
Good morning-

I came across this same issue yesterday, and eventually had to modify some Javascript I found on the Cognos support site.

The following code will override the submit method and only submit if one entry is populated. This javascript is inserted as an HTML Item after the Finish button on your prompt page. For this example the code is looking at the values in 2 text boxes and 1 date w/ the Edit box UI, and only submits if one and only one of the following parameters are populated: 'TEXT_1', 'TEXT_2', or 'DATE'. The Javascript is case-insensitive. The format is slightly different for the text boxes and the date prompt.

Code:
<script>

var cntlName;

function right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else 
    {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// Function to check prompts before submission
function customCheckPage()
{
    var fillCount;

    fillCount = 0;
    for( var i=0; i<preProcessControlArray.length; i++)
    {
        cntlName = eval(preProcessControlArray[i]);

        if (cntlName.m_oSubmitField && cntlName.m_oSubmitField.name.toLowerCase() == 'p_text_1' )
        {
            cntlName.m_oFormField.lostFocus;
            if(cntlName.m_oFormField.value.length >0)
                fillCount++;
        }

        if (cntlName.m_oSubmitField && cntlName.m_oSubmitField.name.toLowerCase() == 'p_text_2' )
        {
            cntlName.m_oFormField.lostFocus;
            if(cntlName.m_oFormField.value.length >0)
                fillCount++;
        }
           
        if (cntlName.m_oSubmit && cntlName.m_oSubmit.name.toLowerCase() == 'p_date' ){
            eval('pickerControl' + cntlName.m_sRef + '.lostFocus()');
            if(cntlName.m_oEditBox.value.length >0)
                fillCount++;
        }
  }

    }
    
    if (fillCount == 1)
        promptButtonFinish();
    else
        alert('Please enter only one of the following: Text 1, Text 2, Date');
}

// Find 'Finish' Button and replace submit method with custom function above
for( var i=0; i<pageNavigationObserverArray.length; i++)
{

    cntlName = eval( pageNavigationObserverArray[i] );
    
    if(cntlName.m_oParent.onclick.toString().indexOf('promptButtonFinish()')>0 )
    {
        cntlName.m_oParent.onclick = customCheckPage; 
    }
}
</script>

Im not sure if this is a default, but on our servers, the administrator had to allow 'HTML Items In report' to the 'everyone' group under the Capabilities tool in Cognos Connection. I haven't tried to do this for any of the other prompts yet. This is the only way I have found to accomplish this so far.

Hope this helps!

--Rob
 
Thanks , I give it a try next week.
Couple of days off for a change.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top