Dynamic Custom Script for Dashboard Filter

Comments

5 comments

  • Avatar
    Nathan Giusti (Edited )

    Hey Bill, 

     

    To be honest I can't really understand your code, but if I understand your use case right, something like this should work

     

    dashboard.on('initialized',function(d) { //Run this script whenever the dashboard is initialized

    var d = new Date();

    var n = date.getMonth();


    if  ([3,6,9,12].includes(n)) { //Check if we are in last month of quarter


    dashboard.filters.update({ //Set the date filter to be next quarter
        jaql:{
            'dim':'[dimDate.Date]'
            'title':'Date',
    'level':'quarter',
            'format':'yyyy QQ',
            'filter':{ 
    'next':{ 
    'count':1,
                    'offset':1
                }
            }
    datatype:'timestamp'
        }
    })
    }
    })

     

    I haven't tested this so there might be some small issues, but I believe this is a good starting point.

    0
    Comment actions Permalink
  • Avatar
    Bill Marty

    Nathan,

    Hey thanks for the help.  I was able to edit some of the syntax (see below) and got the dashboard to recognize this script; yet I am finding the 'count' and 'offset' fields are not coroperating properly: any insight on what values I should put in here to get the filter to be 'Next Quarter" or "This Quarter"? 

     

    Appreciate the help as well; I think its really cool you take time to help me out.  Much appreciated. 

     

    var d = new Date();

    var n = date.getMonth();


    if ([3,6,9,12].includes(n)) { //Check if we are in last month of quarter


    dashboard.filters.update({ //Set the date filter to be next quarter
    jaql:{
    'dim':'[dimDate.Date]'
    'title':'Date',
    'level':'quarter',
    'format':'yyyy QQ',
    'filter':{
    'next':{
    'count':1,
    'offset':1
    }
    }
    datatype:'timestamp'
    }
    })
    }

    0
    Comment actions Permalink
  • Avatar
    Nathan Giusti

    Hey Bill,

     

    It took a little finagling, but I got this working locally

     

    dashboard.on('initialized',function(d) {

    var date = new Date();
    var n = date.getMonth();

    if([3,6,9,12].includes(n)) {
    dashboard.filters.update({ //Set the date filter to be next quarter
    jaql:{
    'column': 'Date',
    'datatype':'datetime',
    'dim': '[DIM_Date.Date]',
    'filter':{
    'next': {
    'count': 1,
    'offset': 1
    }
    },
    'level': 'quarters',
    'table': 'DIM_Date',
    'title': 'My filter'
    }
    })
    }
    })

    Here it is formatted more nicely. It's hard to format code in this thing

     

    0
    Comment actions Permalink
  • Avatar
    Bill Marty

    Nathan,

    This worked for me! I really appreciate you time, effort, and help through this.  You helped me do my job better and I learned some things as well.  Awesome to have this type of support.  Thank you.  

     

    Cheers,

    Bill

    2
    Comment actions Permalink
  • Avatar
    Nathan Giusti

    Thanks for sticking with Sisense! It's a fun tool with a lot of cool things you can do with it. Glad I could help you unlock some of that. 

    0
    Comment actions Permalink

Please sign in to leave a comment.