If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

Javascript to add values to a selection list in version 10.1

Started by Waschb01, 08 Jan 2015 03:14:07 AM

Previous topic - Next topic

Waschb01

Hello
I'm new in this forum and I have only few experiance with Cognos Report

I'm looking for a possibility to add values to a value prompt box at run time with javascript at runtime
I know that for version 10.1 javascript is not official documented and therefore I'm looking for a method of the value-prompt-box object.

To understand the background of my activity:
I have two boxes with date values (From and TO date) and if a user has chosen the from date the available TO dates should only contain younger values.
To do this I delete values in the TO-box if something has changed in the from box (onchange activity)
That works perfect for the first time.
But if the user then wants to go back to older values in the FROM-box I'M missing values in the TO-BOX.
I want to add the former deleted (and in an array saved) values again.
Bu I don't know how??

If someone has an other idea how to dynamicly organize the FROM and TO values please tell me.

Many thanks

navissar

I'm pretty sure this isn't the most effective way of achieving what you want - Using daterange prompt would probably be better and faster - but here's a rough sketch of what you're asking for:
you create an option object, get the prompt, and  add the option. In JS it looks roughly like this (You'll have to embed it in your code on your own):

var opt = document.createElement('option');
opt.text =  displayValue;//this is so you'll see the correct display value
opt.value = useValue;//this is the real value.
opt.dv=displayValue; /*This is so that display value is passed to parameterDisplayValue() fields in report */
fW._oLstChoicesPrompt.add(opt);

Waschb01

Hi

Many thanks for your answer and your proposal.
THe use of a date range prompt is not possible because I take the data out of a file and not all dates are available. (Only dates where a scan was done).

I will try to use the ADD method you told me.

Waschb01

Waschb01

Hello,

Unfortunately I failed with the implementation.
(To be honest I did not understand your construction with the document.createElement('option');
I tried but without success )

So I tried to add direct values from a var into the selection list.
But ADD seams not to be the right method for the selection list object.  :(

And the code at that possition is:
     V_TO.add(V_INS);

V_TO is the handle of the selection list, V_INS is the variable containing the data to be inserted.

The error message is:
'undefined' is null or not an object
The next line:  alert("after adding " + V_INS); is not seen,

The whole code is:
  var V_F = getFormWarpRequest();
    var V_A1  = V_F._oLstChoicesEingabe_Value ;    // Handle to "from-values"
     V_A1.options[2].selected=true;                       // go to the first line of the List
   
     var V_ADD;
     var V_ZW = new Array();                                      // Array to store the data to be deleted
     var V_DIP = "NODATA";                                   //   switch to organize the adding of data
                                                                                  //activities, if there is something new selected
     V_F._oLstChoicesEingabe_Value.onchange = function()
     {                                                                             
         alert("Eingabe geändert");
         alert("Wert V_DIP " + V_DIP);
                                                                           //verify if the TO-list has less data and add these again
          if (V_DIP ==  "DATA")
         {
                alert("now new rows are added ");
                V_ADD = V_ZW.length;                //count the number for the loop
               alert("V_ADD " + V_ADD);

                for (var V_ADD_LOOP = 0; V_ADD_LOOP < V_ADD; V_ADD_LOOP++)
                        {
                        alert("in data adding "); 
                        var V_INS  =  V_ZW[V_ADD_LOOP] ;
                                          alert("now adding: " + V_INS);
                            V_TO.add(V_INS);
                             alert("after adding " + V_INS);


                           V_TO.options[V_TO.length +  1].value  = opt.text;
                   //        V_TO.options[V_TO.length +  1].test  = opt.text;

                         alert("Wert " +V_ZW[V_ADD_LOOP] + " wurde ergänzt");
                      //   alert("Hier würde jetzt ein Wert ergänzt " + V_ADD_LOOP + " " + V_ZW(V_ADD_LOOP).value        );
                          }   
                       alert("Nach dem Datenergänzen");
         }

          var V_FROM_SUCH  =V_F._oLstChoicesEingabe_Value   ; //
          var V_TO  = V_F._oLstChoicesEingabe_Value2;            // handle to list2
           var V_TOLENG = V_TO.length;                                         // number of values in List2
                                                                                                                           //  alert("E2length " + E2leng);

           var V_H1 = 0;                                                       //define a varibale and set 0
                                                                                       //loop though all the values of list2
           for(var V_COUNT=0; V_COUNT < V_TO.length + 3 ; V_COUNT++)                 
                 {                   
                    var     V_DEL =V_TOLENG  - V_COUNT;
                                                    //             alert('Vergleichswerte; ' + E2(count).value  + '  ' +  V_A1.value + ' ' + v_del  );                 
                         if (V_TO(V_COUNT).value  <  V_A1.value )             //compare actual value in list2 with selected value in list1
                         {
                              var V_RE = V_COUNT;
                              V_DIP = "DATA";                     // Set the switch
                                                                                                     // save all the rest values in the new array and delete them from list2
                                                                                //but only for
                               for (V_ZAEHL=0; V_ZAEHL < V_DEL; V_ZAEHL++)
                              {
                                V_ZW[V_ZAEHL] =   V_TO(V_RE).value;                     //save in array
                         //        alert("ZW[v_zaehl]" + V_ZW[V_ZAEHL]);           //display value to be deleted
                                  V_TO.remove(V_RE);                                          //delete from list2
                                }   
                                                                                                          // helploop to display saved values
                               for (V_ARRAY=0; V_ARRAY  < V_ZW.length; V_ARRAY++)
                              {
                            //    alert("gesicherter Wert " + V_ARRAY + " " + V_ZW[V_ARRAY]);       
                               }   
                             
                              break;
                          }
                     }
        }
</script>

Perhaps someone has an idea how to add data with javascript at runtime (or maybe reload the list with original data again)

Many thanks

navissar

Quote from: Waschb01 on 12 Jan 2015 04:09:00 AM
Hello,

Unfortunately I failed with the implementation.
(To be honest I did not understand your construction with the document.createElement('option');
I tried but without success )


Perhaps someone has an idea how to add data with javascript at runtime (or maybe reload the list with original data again)

Many thanks


Yes, someone has an idea. Me. And I gave it to you. I know it to work, to an extent that IBM endorsed a solution I wrote that uses this method. (http://www.ibm.com/developerworks/library/ba-pp-reporting-scripting_techniques-page673/)
So, you did something that isn't what was suggested and it didn't work. Great. Let's try to do what was suggested. If you have a difficulty with something specific in the suggestion, try asking a specific question, rather than asking for someone else's help with another method.
The way to add a value to a value list prompt is by creating an option element, populating its dv, text and value properties, and adding that to the prompt object.
Good luck.

Waschb01

 :-[ ASorry, that is what beginners are doing. (not understanding the hints and advices)

But now I have a new chance and a well documented example.
I only hope it will work in my 10.1!! environment (the document says:
The steps in this document were validated using:

    IBM Cognos 10.2.1.3 using the Go Sales(query) sample package

I come back the next days with my results

Waschb01

navissar

The combo box element behaves the same on 10.1 and 10.2 as far as adding options goes

Waschb01

Hello,

As promised I'm back and this time for me with good results.

I was able to implement the given code.  :D
And so I can recommend it to all who wants to add data in a list.
And I want to take the opportunity to say: MANY THANKS for the help

I now only have the problem, that the format of the date in the list is other than the format of the re-inserted data.
Example:
in the list I have "15 Feb 2013".
But when I save and insert this I get 2013-01-15T00:00:00.000

How can I change this?

Best regards
Waschb01