Archive for April, 2012

Reporting from TM1 – Part6 : JavaScript

April 11, 2012

I prefer to convert one prompt value to another by modifying MUNs with Cognos macros such as prompt and promptmany.

But when these macros are not enough you may try to use JavaScript.

For example suppose you have a month prompt based on a TM1 dimension and YTD prompt. You simply want to select the same month value for month and YTD.

If for some reason it is not possible to convert one to another what you can do is to put your values in the same order into two Value prompts. Then hide one of them.

When the other one is selected hidden prompt will be populated with the item with the same order.  

Put an HTML item after the Back button and put this code:

<script>

function populatePrompts() {

var fW = (typeof getFormWarpRequest == “function” ? getFormWarpRequest() : document.forms);

 

if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}

var listPandLMonth = fW._oLstChoicesp_PandLMonth;

var listPandLYTDmonth = fW._oLstChoicesp_PandLYTDmonth;

 

                for (i = 0; i < listPandLMonth.length; i++) {

                                if (listPandLMonth.options[i].selected) {

                                                listPandLYTDmonth.options[i].selected=true;

                                                break;

                                }

                }

                                                               

                promptButtonFinish();

}

</script>

 

Delete the NEXT & FINISH buttons and put another HTML item with the code:

 

<input type=”BUTTON” class = “bp” onclick=”populatePrompts()” value=”Finish”>

 

Of course the code above is just an example to have the same order in two different prompts. You can modify this code for different selection as below:

 <script>

function populatePrompts() {

var fW = (typeof getFormWarpRequest == “function” ? getFormWarpRequest() : document.forms);

 

if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}

var listPandLMonth = fW._oLstChoicesp_PandLMonth;

var listPandLYTDmonth = fW._oLstChoicesp_PandLYTDmonth;

var listPandLYear = fW._oLstChoicesp_PandLYear;

var k =1;

                for (i = 0; i < listPandLMonth.length; i++) {

                                if (listPandLMonth.options[i].selected) {

                                                listPandLYTDmonth.options[i].selected=true;

                                                break;

                                }

                }

 

                for (i = 0; i < listPandLMonth.length; i++)

                {

                                if (listPandLMonth.options[i].selected)

                                {             

                                                if(i==2){k=2;}

                                                if(i>=3 && i<15){k=3;}

                                                if(i>=15 ){k=4;}

                                                listPandLYear.options[k].selected=true; break;

                                }

                }

 

                                                               

                promptButtonFinish();

}

</script>

 

This code enables to have different selections in the second prompt.

But keep in mind that these JavaScript codes are not supported by IBM.

Advertisements