Cognos Date Prompt Macro Error - cognos

This issues applies to Cognos Report Studio Versions 8.3 through 10.1.1.
In Report Studio 8.3, I've got this raw SQL query running against a MySQL 5.1 data source:
SELECT enc.encounterID, enc.date
FROM enc
WHERE enc.date between #prompt('textPromptStartDate')# AND #prompt('textPromptEndDate', 'date')#
This produces text prompts for the user. If the user enters dates into these prompts in the format of 'YYYY-MM-DD', e.g. '2010-01-15', the query works fine. But I want to replace the text prompts with proper Date prompts. When I try replacing the above prompts with
#prompt('datePromptStartDate', 'date') AND #prompt('datePromptEndDate', 'date')#
the query runs (no errors are generated), but I get an empty result set. I have a feeling I need to adjust the date format that the date prompt macro returns, but I'm stuck after many hours of experimentation as to how to debug this.

For dates, you need the single quotes around the value. I do this using the "sq" function:
#sq(prompt('DateParameterFromPromptPage', 'date'))#

You can create a prompt page with date prompt controls, and then bind them to the parameters in your prompt macros. I tested this out in 8.4 with MySQL 5.1 (ODBC) using the query you have above and it worked. I also had the same problem you experienced with no data being returned prior to creating a separate prompt page and binding the controls.
The steps you would take to do this are:
add a prompt page (if one doesn't exist) to your report
add 2 date prompt controls to the prompt page
in the "Parameter" property for the first date prompt, use: datePromptStartDate
in the "Parameter" property for the second date prompt, use: datePromptEndDate
When you execute the report, the new prompt page will replace the prompt page that is generated from the macro, and the parameters in the macros will be bound to the date controls.
Edit:
I forgot to add that the macros in your SQL should look like the following:
SELECT enc.encounterID, enc.date
FROM enc
WHERE enc.date between #prompt('textPromptStartDate')#
AND #prompt('textPromptEndDate')#

It is possible to create a prompt without a prompt page for the date prompts without using a prompt page. I ran into this exact problem as well on SQL Server until I ran a profile trace. The profile trace showed that Cognos wasn't passing quotes around the date value. I fixed the issue by passing the prompt as a string, replacing the default validation test string (testValue) with a real date, building the string in a variable, and then passing it to the actual query. Here's what I used to convert a date prompt into a normal DATE data type.
DECLARE #StartDate DATE = CONVERT(DATE, REPLACE(#prompt('StartDate')#, 'testValue', '1/1/2012'));

Related

For Cognos 11.1.7 Trying to figure out the syntax for a macro prompt where I can set the default to be all members

Cognos 11.1.7
Need help with syntax on a macro prompt so the default can be to select all members
Here is a simple example that works
set([Generic].[Groups].[Location].[Location] -> ?Location?)
If I wanted to hard code a value I could use this as a slicer
[Generic].[Groups].[Location].[Location]->[all].[1]
What is the syntax for creating a macro prompt with a default of all members?
i.e. instead of ?Location?
Something like this:
#Prompt('Location', 'token', '[all]')#
or maybe like
#Prompt('Location', 'memberuniquename', '[all]')#
Open to using different techniques (filter, set, etc)
Fill in the default text parameter of the prompt macro.
https://www.ibm.com/docs/en/cognos-analytics/11.2.0?topic=macros-mandatory-optional-prompts
"DefaultText
This optional parameter is the text to be used by default. If a value is specified, the prompt is optional.
If you use a space and no values are provided in the Prompt Value dialog box, a Where clause is usually not generated.
If you use text and no values are provided in the Prompt Value dialog box, a Where clause is usually generated using the default value.
Ensure that the text you provide results in a valid SQL statement."
https://www.ibm.com/support/pages/using-prompt-macro-optional-andor-required
You can also set a property in the filter in FM to make it optional.
Both
#Prompt('Location', 'memberuniquename', '[Generic].[Groups].[Location].[Location]->[all].[1]')#
and
#Prompt('Location', 'token', '[Generic].[Groups].[Location].[Location]->[all].[1]')#
should work. You also have the option to set a default value on the actual prompt object.

NetSuite Phone Number Formatting

I am trying to implement automatic phone number formatting into NetSuite I am having some issues getting my script to work. Basically if someone enters a phone number into a customer record, "1234567890" for example, it will automatically format to "(123) 456-7890". You can see my script below along with the error message I receive when creating a new script record.
Fail to evaluate script:
{"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ; before statement (SS_SCRIPT_FOR_METADATA#21)","stack":[]}
Why do you need a script for this? NetSuite already does this, based on the Phone Number Format setting at Setup > Company General Preferences. Check you have this field set correctly according to your preference.
If for whatever reason it turns out you do need a script for this, there are several issues with the script you posted:
There is a syntax error - mismatched parentheses/braces. Your code editor is trying to show you that with the red brace on line 8 and the red squiggly underline on the last parenthesis (line 23).
NetSuite record level client scripts must implement an entry point function. For formatting phone numbers this would be a fieldChanged() entry point. You would need to wrap the logic contained in lines 10 to 20 inside a function, and then reference that in the return statement at the bottom. EG: If you called the function phone() your return statement would be return {fieldChanged: phone}.
You are using SuiteScript 1.0 API functions (nlapiGetRecordId() and nlapiLoadRecord()) in a SuiteScript 2.0 script. Under some circumstances these functions may be available so it might work, but even if it does, it certainly isn't best practice.
Loading the record isn't necessary. When you implement an entry point function, the function is passed a context parameter. IE: function fieldChanged(context). That context parameter contains a reference to the current record (context.currentRecord). Work with that instead of attempting to load the record separately.

Is there a way to suppress a prompt asking for query parameters when updating a data source (SAP) from an excel macro?

I am updating a data source from an excel macro by running
Application.Run("SAPExecuteCommand", "RefreshData", "DS_1")
, which generates a prompt asking for the user to input query parameters. However, I just want to go with the already set parameters. Is there a way to suppress the prompt altogether or perhaps effectively just click OK when prompted? (perhaps finding the element that is the OK button and clicking it from the same macro, without resorting to absolute coordinates?)
The prompt that I want to suppress or obviate
I believe you should pre-populate some of the fields and save the file. Some of the fields are mandatory, and maybe you have not filled them all out in the file you are loading and refreshing.
I am using Call Application.Run("SAPExecuteCommand", "RefreshData") similarly, and I do not get a dialog box.
You could also try to set variables and then execute a refresh from within VBA using
Call Application.Run("SAPSetVariable", "my_variable", value, "INPUT_STRING", "DS_1")
Call Application.Run("SAPExecuteCommand", "RefreshData")

Prompt Page Requires Entry, Required set to No

I have a report that I developed that utilizes render variables as described here.
My prompt page has 3 check box groups filled with variables. My first box is set to required, as it contains key information that needs to be pulled. The 2nd and 3rd have optional values. When the report runs, it requires at least one of the options in box 2 and 3 to be selected.
Any idea?
If a parameter is referenced directly in a query data item, Cognos will force it's associated prompt to be required even if you set it to 'Optional'. If this is the issue, the solution is to use a prompt macro instead of the normal ?? syntax. You set a default value to pass if the prompt isn't satisfied. This allows the prompt to act like an optional prompt.
The minimum syntax is:
#prompt('prompt_name','string','')#
The third parameter is the default value. I have just used an empty string here but you could change this to whatever you want.

Why we need the optional parameter queryItem in Cognos promptmany

In this page:
http://publib.boulder.ibm.com/infocenter/c8bi/v8r4m0/index.jsp?topic=/com.ibm.swg.im.cognos.ug_fm.8.4.0.doc/ug_fm_id9744using_macro.html
We have:
QueryItem
This parameter is optional. The prompt engine can take advantage of the Prompt Info properties of the query item. Descriptive information can be shown, although the prompt value is a code.
I am having trouble understanding this part :
The prompt engine can take advantage of the Prompt Info properties of the query item. Descriptive information can be shown, although the prompt value is a code.
The promptmany syntax will ultimately generate a where clause. So how can it use the properties of the Query Item?
The prompt generation in the front end uses this parameter, not the query engine. This parameter makes no difference to the where clause. It is basically a hint to the prompt engine to tell the front end when it tries to automatically build a prompt.
I never fill in this parameter when I use prompt macros.

Resources