Cognos Analytics

Cognos Analytics

Connect, learn, and share with thousands of IBM Cognos Analytics users! 

 View Only
Expand all | Collapse all

Data insertion in table

  • 1.  Data insertion in table

    Posted Wed June 21, 2023 05:34 AM

    Hello All,

    I am generating a list report from cog nos report studio. 

    I need to insert data from list report to internal database table.

    Please suggest how to insert report data into tables.



    ------------------------------
    Nidhi Pawaiya
    ------------------------------


  • 2.  RE: Data insertion in table

    Posted Wed June 21, 2023 05:50 AM

    Hi,
    there are several ways to do that. One is to create a stored procedure on your RDBMS and import this into our package/datamodule. You have to link the input parameters of the procedure to your Cognos data via prompt parameters/macros. Here's an example of how I use this setup to let users maintain currency exchange rates in a DWH table:

    This is a way that is suitable for single data record actions. If you want to have it more convenient I suggest to use 3rd-party software like Apparo Fast Edit (small environemnts are free of charge).

    https://accelerator.ca.analytics.ibm.com/bi/?pathRef=.public_folders%2FIBM%2BAccelerator%2BCatalog%2FContent%2FTOL00016

    Hope this helps a bit.



    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 3.  RE: Data insertion in table

    Posted Thu June 22, 2023 02:19 AM

    Thank you So much Robert, Let me try to implement, the way you have suggested. Thanks



    ------------------------------
    Nidhi Pawaiya
    ------------------------------



  • 4.  RE: Data insertion in table

    Posted Thu June 22, 2023 08:23 AM

    robert dostal - can you show some screen shots of how your executed report look and how the client enters the rate? i am having a hard time visualizing the finished product. 



    ------------------------------
    brenda grossnickle
    BI Programmer Analyst
    FIS
    ------------------------------



  • 5.  RE: Data insertion in table

    Posted Thu June 22, 2023 10:31 AM

    Hi @brenda grossnickle 

    sure thing.

    I've created two reports: one with the list of the current data records in the exchange rate table and a second one with three pages – one for each action (insert, update, delete). Both reports are linked by drill-troughs with parameter/data item transfer.

    This is the overview list of the table and the last three columns have these small icons that hold the drill-trough definitions.

    The target report gets an action parameter from the source report that is linked to a render variable. Each single value shows only one of the appropriate pages and "tells" the report which action the user wants to perform.

    The pages then have also list objects that only show one single data record (filtered by the parameter values from the source report) and additional columns with a text prompt and a drill-trough on itself which then transfers the new value to the stored procedure.

    That's an example for the update page:

    And one for the page to delete records. I've added a security question to be sure the user wants to delete it.

    On each page, all objects are in a conditional block that is linked to a boolean variable. It captures if the user has clicked the action button or not and if yes, shows the result "STATUS" as Singleton from the stored procedure.

    I know that I've could have created a much simpler report with additional value prompts instead of drill-troughs but the users are happy with this set up already.

    Hope this helps a bit.



    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 6.  RE: Data insertion in table

    Posted Thu June 22, 2023 01:18 PM

    did you have to use any java script?



    ------------------------------
    brenda grossnickle
    BI Programmer Analyst
    FIS
    ------------------------------



  • 7.  RE: Data insertion in table

    Posted Fri June 23, 2023 01:58 AM

    Nope, I didn't :)



    ------------------------------
    Robert Dostal
    Team Leader BI
    GEMÜ
    Ingelfingen
    ------------------------------



  • 8.  RE: Data insertion in table

    Posted Fri June 23, 2023 10:16 AM
    Edited by brenda grossnickle Fri June 23, 2023 02:02 PM

    I am doing a cognos report that updates a ms sql database table. My report uses many of the techniques that Robert Dostal has posted, except mine is a simple toggle update. There is no data entry. If a relationship code type (single, joint owner) is = 0 in the database table, when clicked it is updated to 1, and visa versa. The report is a drill through that redesplays the same report - report1 is a drill through to report1.

    First row is just for my testing. it will be removed. Three prompt text boxes that have -99 will be hidden. Userid is a badly named column that should be called something like primary key. Userid column will be hidden. First prompt box is for the userid and -99 says to show all rows, second prompt box is for Single Owner, third prompt box is for Joint Owner. The relationship table has userid, Relationship Code, Single Owner, and Joint Owner column. Relationship code BEN can be assigned to Single Owner and/or Joint Owner. So my update is just a toggle - on or off. It does not allow for entering text. If in the relationsihp table BEN, Single Owner = 1 then "Assigned" is displayed, else "[+]" is displayed. 

    An example would be when BEN Single Owner is clicked, it is a drill through, and a stored procedure that is setup in framework manager is called and two parameters are passed - userid = 2 and single owner. Joint Owner parameter is not passed. In the stored procedure userid=2, singleowner is not null and joinowner is null. So the stored procedure knows that BEN (userid=2) Single Owner (parameter for single owner is not null) was clicked. So the stored procedure would set BEN SingleOwner to 1 if it is currently 0 in the table, else it would set it to 0 (toggle). And then the drill through redisplays (select * from relationship) the same report again and BEN Single Owner now displays "Assigned".

    Here are some links that i used. Some are only a toggle (like mine), some allow data entry (i did not like because you could only do one row at a time and you have to redisplay the report to see the update or to continue updating), some use HTML and  javascript. 

    https://www.youtube.com/watch?v=00xaDWs5igo    -- i used this one the most for my report. he only had a single update column. i modified to update two columns.

    https://www.youtube.com/watch?v=fnIwARI5BnU     - this one is more of primer of how to use stored procedures in framework manager

    https://www.youtube.com/watch?v=9RxDg7LIWQI  - data entry (not just a toggle) to update database table

    https://cognospaul.com/tag/framework-2/  - pretty advance data entry using html and java script



    ------------------------------
    brenda grossnickle
    BI Programmer Analyst
    FIS
    ------------------------------



  • 9.  RE: Data insertion in table

    Posted Sun June 25, 2023 03:50 AM

    Since I've written that article my JS skills have improved dramatically. One of these days when I have free time (HAH) I need to write an article describing a method to do data entry using AJAX so you don't have to refresh the page. 

    Basically you can have a separate report that runs the stored procedure. You can then use CMS to call it, passing the parameters. But the CMS call can be handled through an event handler on the report the user is running. An example would be to have an onblur listener on all inputs in your list. When the user removes focus from the input the stored proc report is called in the background. 

    Depending on interactive mode you have different techniques to get the context data for the cell the user is updating. In interactive mode you can run Application.getParamterValues() to get a list of all active parameters for the report run, so you can get the prompted time/product/region values for example. 



    ------------------------------
    Paul Mendelson
    ------------------------------



  • 10.  RE: Data insertion in table

    Posted Fri February 16, 2024 10:50 AM

    Hi Paul, love your work BTW. For your example is there any way to do more than one 'value' field? for instance, a value1, value2, value3 etc.. ? so the user updates the first, second and third value item fields then those three get submitted to the database table? 



    ------------------------------
    M Barrett
    ------------------------------



  • 11.  RE: Data insertion in table

    Posted Tue February 20, 2024 05:12 AM

    There are a few ways you can do this. The way I'm picturing it is you have a series of three inputs in a row. You could then write an onblur function to attach to all of the inputs that would do something like this

    fnUpdate = async function(){
      var elm = this
        , row = elm.closest('tr')
        , inps = [...elm.querySelectorAll('input')]
        , gateway = Application.GlassContext.gateway
      , targetReport = `/content/folder[@name='CMS']/report[@name='c']`
        , url = gateway + '/v1/disp/rds/reportData/searchPath' + targetReport 
      ;
      
    if(inps.filter(inp=>inp.value).length<inps.length) return false; //count the inputs with values. If not ALL of the inputs are filled stop
      
      var params = inps.map(inp=>{let param = 'p_' +inp.name+'='+inp.value }).join('&')
      var data = await fetch(url + '?asyc=off&fmt=datasetJSON&'+params
        , {
            "headers": {
                "accept": "application/json"
              , "content-type": "application/json"
            }
        , "method": "get"
        , "mode": "cors"
        , "credentials": "include"
        }).then(x=>x.json())
      
      return data
    }

    The assumption here is that each input has the parameter as the input name. The HTML would be like: <input name="pYears"/>
    What is happening is that when the user enters a value into any input on the list, the JS goes up to the row and looks for all of the inputs. It then compares the count of all inputs with values against the count of inputs. If they match, it will run the update report, passing the parameters in the URL. The URL will look something like this: 

    "/bi/v1/disp/rds/reportData/searchPath/content/folder[@name='CMS']/report[@name='Run Update Stored Proc']?asyc=off&fmt=datasetJSON&p_pYear=2022&p_pProductline=660&p_pCountry=America"

    This is the basic script to handle it. You can then add things like indicators if they haven't populated all of the inputs (maybe make each unfilled input background or border red), or spinning icons while the row is being updated. You could get even more fancy and only generate the input when the user clicks on the cell - but then you'd have to refactor the input count check. 


    ------------------------------
    Paul Mendelson
    ------------------------------



  • 12.  RE: Data insertion in table

    Posted Tue February 20, 2024 11:16 AM

    Thank you Paul for the prompt response!

    Is this in addition to what you have in this example or is it a new set up?

    https://cognospaul.com/2014/01/02/creating-data-entry-page-cognos/



    ------------------------------
    M Barrett
    ------------------------------



  • 13.  RE: Data insertion in table

    Posted Tue February 20, 2024 12:23 PM

    This would be a combination. Same idea using a stored procedure with parameters, but calling the report with mashup services so it all happens in the background. This makes the experience much better for the end user, as the report doesn't need to be refreshed for the data to be updated. 



    ------------------------------
    Paul Mendelson
    ------------------------------



  • 14.  RE: Data insertion in table

    Posted Tue February 20, 2024 01:43 PM

    I don't mind the refresh, would love to just finish it the old way :-). Can I add two more value fields in the SP and table with prompts and then in the HTML of the fields change it to point to value1 or value 2?

    '<input 
      type="text" 
      name="p_'+number2string([DataEntry].[Day Key])+'Value" 
      value="'
    +case when [Value] is null then '' else number2string( [DataEntry].[Value2]) end
    +'"
      onchange="updateDateArr('+number2string([DataEntry].[Day Key])+')"
    />'



    ------------------------------
    M Barrett
    ------------------------------



  • 15.  RE: Data insertion in table

    Posted Thu February 22, 2024 03:33 AM

    Yeah, that should definitely work. As long as the report is getting a value for the parameter that matches the parameter in the stored procedure it will be inserted.



    ------------------------------
    Paul Mendelson
    ------------------------------



  • 16.  RE: Data insertion in table

    Posted Fri February 23, 2024 03:54 PM

    Yep, worked! Thanks Paul!!!



    ------------------------------
    M Barrett
    ------------------------------



  • 17.  RE: Data insertion in table

    Posted Sun February 25, 2024 04:52 AM

    This technique to create parameters with HTML-Items is not working in interactive viewer. At least it did not work in my tests. Is there something similar for the "new" viewer? 



    ------------------------------
    Gerhard Lang
    ------------------------------



  • 18.  RE: Data insertion in table

    Posted Tue February 27, 2024 08:17 AM

    This method doesn't work in Interactive Mode, and I haven't been able to find a good way of dealing with this without JavaScript. For interactive mode what I recommend is writing a function that will loop over each of the inputs and then kick off a Cognos Mashup Services request on blur - when the user clicks or tabs out of the input.

    Take a look at this quick example I wrote:

    define([], function () {
      "use strict";
      class runMashup {
        constructor() {
        }
    
        initialize = (oControlHost, fnDoneInitializing) => {
          let o = oControlHost.configuration ?? {}
            , targetReport = o.targetReport ?? `/content/folder[@name='PMsquare%20Content']/folder[@name='Paul']/report[@name='CMS%20Target']`
            , targetList  = oControlHost.page.getControlByName(o.targetList)
            , inputs = targetList.element.querySelectorAll('input')
          ;
          
          inputs.forEach(x=>{
            x.onblur = runFetch.bind(this,JSON.params = JSON.parse(decodeURIComponent(x.dataset.params.replaceAll('+',' '))),targetReport,x)
          })
          fnDoneInitializing();
        }
        
        runFetch = (params,targetReport,inp)=>{
          let paramString = '&'+params.map(x=>x.name+'=<![CDATA['+x.value+']]>').join('&')
            , comment = `&p_Comment=<![CDATA[${inp.value}]]>` 
            , url = `${Application.GlassContext.gateway}/v1/disp/rds/reportData/searchPath/${targetReport}?fmt=datasetJSON&async=off${paramString}${comment}`
          ;
          
          fetch(url, {
          "headers": {
            "accept": "application/json, text/javascript, */*; q=0.01",
            "accept-language": "en-US,en;q=0.9",
            "x-requested-with": "XMLHttpRequest"
          },
          "method": "GET",
          "mode": "cors",
          "credentials": "include"
          })
          .then(x=>x.json())
          .then(x=>alert(JSON.stringify(x)))
          
        }
    
      return runMashup;
    
    });
    
    
    

    The target report should contain the stored procedure feeding a list on the page. Target list is the name of the list on the report that contains the inputs, and each input should look like this:

    '<input name="Comment" data-params="'+URLEncode('[{"name":"p_ProductLine","value":"'+[Query1].[Product line]+'"},{"name":"p_Year","value":"'+number2string([Query1].[Year])+'"}]')+'" />'

    Or at least similar. What this will do is have the input contain the context information when the stored procedure is run. In my example I'm passing Product line, year, and comment, every time the user adds a new comment. When the user clicks off the input the runFetch function is triggered, converting the parameters and comment into a valid URL for fetch.

    https://cognos.pm2analytics.com/sandbox/bi/v1/disp/rds/reportData/searchPath//content/folder[@name='PMsquare%20Content']/folder[@name='Paul']/report[@name='CMS%20Target']?fmt=datasetJSON&async=off&p_ProductLine=%3C![CDATA[Golf%20Equipment]]%3E&p_Year=%3C![CDATA[2010]]%3E&p_Comment=%3C![CDATA[example comment]]%3E

    This runs the stored procedure report, passing the parameters needed. 



    ------------------------------
    Paul Mendelson
    ------------------------------