Cognos Analytics

Cognos Analytics

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

 View Only
  • 1.  Set Custom Default value for Date Prompt

    Posted Fri April 07, 2023 08:59 AM

    Hi,

    My business requirement is to set default value for two date prompts. For example Jan 1st of the current year (Jan 1, 2023) and last date of previous month (March 31, 2023).

    I am wondering if this is possible without writing a java script.

    If java script is the only route to accomplish this, does java script have to be written and hosted on the server and then javascript file referenced using Custom Control or can I just write a local java script in HTML item?

    Thanks.



    ------------------------------
    Raman Singh
    ------------------------------


  • 2.  RE: Set Custom Default value for Date Prompt

    Posted Tue April 11, 2023 11:36 AM
    Edited by Patrick Neveu Tue April 11, 2023 11:41 AM

    Hi Raman,

    I assume the easiest way is to use JavaScript.

    You can use an extension to load the .js file (for instance DatePromptPresets.zip located in <install_location>\analytics\samples\extensions\Extensions for Custom Controls)
    or
    You can use a custom control that will reference your javascript file (for instance, /bi/samples/js/DatePromptPresets/DatePromptPresets.js)

    There is one report (from the Samples) you might want to test, it is called: "Date prompt presets"

    You might test from this URL:
    IBM Accelerator Catalog

    Best regards,



    ------------------------------
    Patrick Neveu
    Positive Thinking Company
    IBM Champion
    ------------------------------



  • 3.  RE: Set Custom Default value for Date Prompt

    Posted Mon April 17, 2023 01:06 PM

    Hi Patrick,

    Thanks for your guidance. I will give it a try and get back if I have any questions.

    Thanks,

    Raman



    ------------------------------
    Raman Singh
    ------------------------------



  • 4.  RE: Set Custom Default value for Date Prompt

    Posted Mon April 17, 2023 04:57 PM

    Raman, 

     

    I always use an expression in my filters to add a default prompt feature.  Just pulled one as an example below.  [PLANNED_DISPATCH_DTTM] is a column I filter the underlying query by.  pFROM_DATE is the name of the prompt value I define in the expression.  The rest is where I default to [PLANNED_DISPATCH_DTTM] of yesterday's date or greater.  Once I put that in my filter expression on the query, then I create the prompt object and tie it to the FROM_DATE that is named/created with this expression saved as a filter. 

     

    CAST([PLANNED_DISPATCH_DTTM],DATE) >= (#PROMPT('pFROM_DATE','DATE','(_ADD_DAYS(CURRENT_DATE,-1))')#)

     

     

    Logan Whitaker

    PMO, HEB Supply Chain Planning & Operations

    o: 210.938.6043  m: 210.429.3181

    e: whitaker.logan@heb.com

     






  • 5.  RE: Set Custom Default value for Date Prompt

    Posted Wed April 19, 2023 10:13 AM

    Hi Logan,

    Appreciate your reply.

    Unfortunately I am unable to understand what you are trying to do here.

    Is it possible for you to provide a step by step. Here is my requirement. Default Start Date Prompt to 1st calendar day of previous fiscal year and End date to last calendar day of previous fiscal year. So if I run the report today the user should see Jan 1 2022 and Dec 31 2022 in From and To dates respectively on the prompts page. And they should be able to change it if needed and the report should filter data accordingly.

    The field name in the cognos framework package on which I am trying to create this prompt is Payment Date.

    Thanks,
    Raman



    ------------------------------
    Raman Singh
    ------------------------------



  • 6.  RE: Set Custom Default value for Date Prompt

    Posted Wed April 19, 2023 09:54 AM

    Hi Patrick,

    I tried but it did not work. Can you please review the below:

    First of all here is the version (IBM Cognos Analytics 11.0.13.1 (LTS)) I am working on, as per the link I believe this functionality is available 11.2 onwards.

    If the version thing is fine, here is the script and path I used.

    Module Path - ../v1/ext/DatePromptPresets/DatePromptPresets1
    UI Type - UI without event propgation

    Script for DatePromptPresets1.js- 

    define(function () {
        "use strict";

        var oPage;

        function setDatePrompt() {
        };
    function setDatePrompt() {
            // Create a prompt object using the prompt name set in Report Studio
            oPage = oControlHost.page;
            var datePrompt = oPage.getControlByName("DatePrompt");
            // Set the prompt values using the JSON encoded dates
            datePrompt.clearValues();
            datePrompt.setValues('2022-01-01');
        };

    I have tried around playing with JS but no matter what code I try it does not seem to be working. For starters I am just trying to set it to a constant date of '2022-01-01' just to try and make it work.

    Thanks,
    Raman



    ------------------------------
    Raman Singh
    ------------------------------



  • 7.  RE: Set Custom Default value for Date Prompt

    Posted Wed April 19, 2023 10:21 AM

    Hi Raman,

    Here are a few topics you should read regarding how to setup the samples:
    https://community.ibm.com/community/user/businessanalytics/blogs/steven-macko/2018/09/10/javascript-samples-for-ibm-cognos-analytics

    I guess it should be useful, specially the part below:

    Best regards,



    ------------------------------
    Patrick Neveu
    Positive Thinking Company
    IBM Champion
    ------------------------------