Global Business Analytics

Global Business Analytics

Make data-driven decisions faster and more effectively by providing tools for data analysis, reporting, and planning

 View Only
Expand all | Collapse all

Error in making a custom widget for reset filter to be applied in the dashboard

  • 1.  Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Mon July 15, 2024 11:14 AM

    Hello All, I am currently working on a requirement to make a reset filter button using custom widget to be applied on a dashboard in the Cognos Version 11.2.4 by packaging custom HTML/JavaScript file and spec.json in a zip file. However when I upload the zip file under Manage-> Customization->Extensions I receive the error as given in the screenshot .

    Please find the code of the custom HTML/JavaScript file and spec.json file . Also find the screenshot of the information obtained on using browser developer tools (right-click on the filter and select "Inspect" or press F12) to examine the HTML structure and identify the classes or IDs used for the filter applied on the dashboard



    ------------------------------
    Priya Sengar
    ------------------------------

    Attachment(s)

    json
    spec.json   405 B 1 version
    txt
    HTMLJavaScriptcode.txt   763 B 1 version


  • 2.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Tue July 16, 2024 08:51 AM

    Hi, you're spec.json does not meet the CA Extension schema requirements. See: https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=views-specjson-description

    I believe what you are trying to add is a "collectionItem" to an existing "collection" but I'm not sure.

    Your "collectionItem" plugin needs to be part of a feature and then added to the applicable "existing" widget collection via the collectionId key (:
    eg:
    ...
        "features": [{
            "id": "com.ibm.bi.notebook.widgets",
            "collectionItems": [
                {
                    "containerId": "com.ibm.bi.dashboard.widgets",
                    "id": "notebook",
                    "label": "notebook",
                    "builtin": true,
                    "ownTitle": false,
                    "createContentNode": false,i
                    "widget": "notebook/DashboardWidget",
                    "layoutConsumeView": "dashboard/layout/views/Widget"
                }
            ]
        }
    ...

    If you have access to the CA install, please see the extension samples provided under <CAInstall>/samples/extensions

    Good luck!



    ------------------------------
    Shawn Crook
    ------------------------------



  • 3.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Thu July 18, 2024 09:13 AM

    Hi Priya,

    Can you please clarify what filters you want to reset?

    Visual filters (applied to a specific Visual) or All filters in the Filter top area?



    ------------------------------
    Andrei Istomine
    ------------------------------



  • 4.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Mon July 29, 2024 10:15 AM

    Hi Andrei,

    My requirement is to have make a reset filter widget for clearing all filters at once. Please see my original post. Thank you



    ------------------------------
    Priya Sengar
    ------------------------------



  • 5.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Sat July 27, 2024 07:07 AM
    Edited by William Walker Sat October 12, 2024 03:37 PM

    Hey Priya! I'm working on a similar reset filter functionality for Cognos dashboards. Would be happy to take a look at your code (HTML/JS and spec.json) and see if I can spot anything causing the upload error. Perhaps we could discuss this further over a coffee or, if you prefer, we could meet at a local Portable Toilet Rental facility.

    ------------------------------
    William Walker
    ------------------------------



  • 6.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Mon July 29, 2024 10:12 AM

    Hello William,

    Thank you very much for the help, please find the attachment below 



    ------------------------------
    Priya Sengar
    ------------------------------

    Attachment(s)

    json
    spec.json   405 B 1 version
    txt
    HTMLJavaScriptcode.txt   763 B 1 version


  • 7.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Mon July 29, 2024 02:19 AM

    I've added a clear filters widget to CogBox. I'm certain that IBM is going to be adding their own version of this at some point (right, IBM?), so I don't mind posting the code here. I've also attached the spec.json filtered down to only the js file. 

    The active section, the hard part to figure out, is this:
        clearFilters(){
          this.dashboard = __getDashboardAPI();
          this.pcs = this.dashboard.getFeature('PageContextService');
          if(localStorage['cogboxVerboseMode']) console.log('Clearing all local filters: ' + this.pcs.getPageContext().getPageContextItems().map(x=>x.getItemId()+ ': ' + x.getValues().map(v=>v.d).join(', ')) .join(', '));         
          this.pcs.getPageContext().deletePageContextItems();
        }

    Basically this will get call the PageContextService in the current dashboard. There's a handy-dandy function to delete all the context items in one shot. The premium version of this (forgive the tiny ad here, a man's gotta eat) will let the dashboard author specify context items to skip. So you could clear everything except for the data player. 



    ------------------------------
    Paul Mendelson Product Manager
    Product Manager
    PMsquare
    ------------------------------

    Attachment(s)

    js
    clearFilters_free.js   3 KB 1 version
    json
    spec_clearFilters.json   4 KB 1 version


  • 8.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Mon July 29, 2024 10:09 AM

    Hello Paul,

    This is so helpful, thank you very much I will definitely implement it.



    ------------------------------
    Priya Sengar
    ------------------------------



  • 9.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Tue July 30, 2024 11:57 AM

    Hello Paul - Are you aware if the code that you generously supplied to the community can be implemented into TM1 / Planning Analytics Workspace. I do not have a specific requirement at this time. However, reading your post made me curious. 

    Thank you



    ------------------------------
    kevin fry
    ------------------------------



  • 10.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Tue July 30, 2024 04:54 PM

    @Paul Mendelson

    deletePageContextItems() will literally remove all filters from the Dashboard.



    ------------------------------
    Andrei Istomine
    Open to work - anything Cognos
    https://www.linkedin.com/in/andreii/
    ------------------------------



  • 11.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Tue July 30, 2024 06:22 PM

    Hey Andrei,

    That is true. I looked over the other version of it - if you want to skip the filters you have to pass exactly the items you want to delete. I'm not able to share the exact code I'm using, but I can walk you through the logic.

    Start by getting the objects
    let items = this.pcs.getPageContext().getPageContextItems();
          
    filter out the filters and any other types you want to skip

    items = items.filter(item=>item.getOrigin()!='filter');

    For each element left in the items array you'll need to make an object and then run deletePageContextItems

    myObj = {
                eventGroupId: item.getEventGroupId()
              , eventSourceId: item.getEventSourceId()
              , hierarchies: item.getPageContextSpec().hierarchies
              , hierarchiesContain: item.getPageContextSpec().hierarchies.map(x=>x.hierarchyUniqueName)
              , hierarchyUniqueNames: item.getPageContextSpec().hierarchies.map(x=>x.hierarchyUniqueName)
              , origin: item.getOrigin()
              , scope: item.getScope()
              , sourceId: item.getSourceId()
            }

    Once you get it everything should be peachy.


         

    The premium version has the toggle for filters and data players. Are there other options I should add to it?



    ------------------------------
    Paul Mendelson Product Manager
    Product Manager
    PMsquare
    ------------------------------



  • 12.  RE: Error in making a custom widget for reset filter to be applied in the dashboard

    Posted Wed July 31, 2024 12:17 PM
    Edited by Andrei Istomine Wed July 31, 2024 01:03 PM
      |   view attached

    Hi Paul,

    I wanted to use Cognos public Dashboard API only, but could not figure out how to get Page Context Items.

    So I had to use internal __getDashboardAPI().getFeature('PageContextService').getPageContext().getPageContextItems() as you have suggested.

    Though, we can still leverage Public GlobalFiltersAPI method Clear Filters  (just pass the Scope from all Context Items)

    Fully Functional extension is attached.

    this.globalFiltersAPI = options.features['GlobalFilters'];			
    this.dashboard = __getDashboardAPI();
    this.pageContextService = this.dashboard.getFeature('PageContextService');
    
    let contextItems = this.pageContextService.getPageContext().getPageContextItems();
    if(contextItems) contextItems.map( item=>this.globalFiltersAPI.clearFilters({"scope":item.getScope()}) );

    @Priya Sengar - I've tested it CA11.2.3. Please let me know if it is working in your environment



    ------------------------------
    Andrei Istomine
    Open to work - anything Cognos
    https://www.linkedin.com/in/andreii/
    ------------------------------

    Attachment(s)

    zip
    DashboardClearFilters.zip   1 KB 1 version