IBM Cognos Report Studio: Value prompt default selection from prompt "default text" parameter - cognos

I have a value prompt that references the parameter 'Year_Parameter', and a list with one column (a Data Item Expression) that references the same parameter as the value prompt in this way:
#prompt('Year_Parameter')#
The value prompt has some static choices: 2011, 2012 and 2013.
Hence, when I run my report, and enter 2012 in the prompt page that pops up before the report page is shown, 2012 has automatically been selected in the value prompt from its list of choices when the report page is shown.
Furthermore, if I put 2012 in the list of default selections, no prompt page is shown, and 2012 has also now automatically been selected for the value prompt when the report is shown.
However, if I remove 2012 from the list of default selections, and change my Data Item Expression to either of these expressions:
#prompt('Year_Parameter', 'token', '2012')#
#prompt('Year_Parameter', 'token', 2012)#
#prompt('Year_Parameter', 'string', 2012)#
#prompt('Year_Parameter', 'string', '2012')#
... no prompt page pops up as when 2012 were specified as the default selection, but no value is automatically selected for the value prompt. The value prompt shows its default Header Text: The parameter name - Year_Parameter".
Remember the prompt function definition:
prompt ( prompt_name , datatype , defaultText , text , queryItem ,
trailing_text )
Anyone know why this is happening, and more importantly a solution for how to be able to select the default selection for the value prompt, by specifying it in the Data Item Expression?
Is it because the prompt() macro only attempts to fetch the value of the parameter 'Year_Parameter', but in itself does not fill the parameter with a value? The parameter must be given by some value prompt (on a prompt page or embedded in a report page).
Hence, the defaultText argument to the prompt function, will NEVER fill the parameter itself, but be returned by this specific prompt function in cases where the parameter has no (valid) value?
Thank you very much in advance for any input!
Edit: Found this explanation on how to dynamically assign a default value to parameters.
http://cognosknowhow.blogspot.no/2013/04/how-to-dynamically-set-up-default-value.html
Final: I ended up using the following Javascript to dynamically select value prompt and update the report:
<script type="text/javascript">
// This function updates the report dynamically for the current year
// The function is wrapped inside a setTimeout call in order to avoid an error caused by too frequent requests
setTimeout(function updatePrompt() {
var oCR = cognos.Report.getReport("_THIS_");
var yearPrompt = oCR.prompt.getControlByName("YearPrompt");
var selectedValue = yearPrompt.getValues()[0];
if (typeof selectedValue === "undefined") {
currentYear = new Date().getFullYear();
yearPrompt.setValues([{'use':currentYear}]);
// Update report
oCR.sendRequest(cognos.Report.Action.FINISH);
}
}, 50);
</script>

Exactly, as Skovly is saying, the prompt macro can't fill in the value to the parameter. From the link provided I'd choose javascipt (first option) but keep in mind IBM changes the syntax from version to version.
(I don't know yet how to post comments on answers, otherwise I'd attach it to the previous one to stregthen the opinion that you can't do what you want with prompt macro).

Related

How to display default value from prompt macro in value prompt CA11?

I was wondering if it is possible to display the default value from a prompt macro in a Value prompt. My prompt macro looks like this "#prompt('pMonth','MUN','[Previous Month]')#"
so my goal in the value prompt would be to have 202103 displayed instead of header text name which I have named "Previous Month"
I tried with an old javascript from Cognos 10 where you desc the Months and specify what index it should pick but the issue with that code is that everytime you try to change to a different month the report re-runs and loops back to to the same Index value.
<script>
var theSpan = document.getElementById("A1");
var a = theSpan.getElementsByTagName("select"); /* This stmt return an array of all value prompts within span */
for( var i = a.length-1; i >= 0; i-- ) /* now loop through the elements */
{ var prompts = a[i];
if( prompts.id.match(/PRMT_SV_/))
{ prompts.selectedIndex = 2; } /* This selects the second options from top */
canSubmitPrompt();
}
</script>
All solutions, tips and ideas are highly appreciated.
Best regards,
Rubrix
For Cognos Analytics, running with full interactivity, you probably need a Page Module. Check out IBM's Scriptable Reports documentation for Cognos Analytics. You'll want to craft your script to use the current parameter value as default (if you can get it), then fail over to your default value from the data. You will probably need to integrate this with a Custom Control to be able to get that default value from the data.

Label gets selected on clicking enter key in the tabulator cell

I have a js fiddle to show the issue that I am facing.
Tabulator 'email' column has freetext set to true to allow the user to set the value of the cell to a free text entry as follows:
editorParams:{
values:{
"steve#boberson.com":"steve",
"bob#jimmerson.com":"bob",
"jim#stevenson.com":"jim",
"harvy#david.com":"Harvy",
"ken#thompson.com":"Ken",
"denny#beckham.com":"Denny"
},
freetext:true,
searchFunc:function(term, values){
console.log("term and val "+term +" \n"+values);
var matchedEntries = {};
var matchFound = false;
for(var key in values) {
if(key.includes(term)){
matchFound = true;
matchedEntries[key] = values[key];
}
}
if(matchFound){
return matchedEntries;
}
else{
return {term: term};
}
}
}}
Select one of the values from the selector list displayed, say steve, value being 'steve#bobberson.com'.
Then after the value is selected, click on the same tabulator cell, the value displayed suddenly changes to the label.When user clicks enter key now, the label is selected instead of the value,.ie. steve will be displayed instead of steve#bobberson.com
If this is not a bug, how do I make sure that the value steve#bobberson.com remains selected after clicking enter. This is because freetext option is set to true in the editorParams of the column
Attached a gif showing the issue
That is not a bug,
With freetext enabled, users are able to enter any text they like in that field and it will be saved which is exactly what is happening in the example
If they select the email address again from the list then it is correctly saved.
It is an either/or scenario, you can either restrict the users to selecting specific values from the list OR you can allow them freetext in which case anything goes.
If you want a different behaviour then you can always build a custom editor that works in the way you want. Checkout the Custom Editor Documentation for more information

How to show and update current page number in an input box palceholder Using Tabulator

I am trying to show the current page number in an input box as a place holder the issue is I can't figure out how to update the value when users go to another page.
Here is what I tried:
<input id="currentPage"/>
document.getElementById("currentPage").placeholder = tabulator_table.getPage();
Here is the first part of the question
Here is sample
You want to use the pageLoaded callback on the table instance.
When creating the table, you need to add a property for pageLoaded as a function with a parameter for the page number. This callback is triggered each time the page is loaded.
Here is a working example, https://jsfiddle.net/nrayburn/w68d75Lq/1/.
So you would do something like this, where #table is the element id for the table and input is a reference to your input element where you keep the page number value.
new Tabulator('#table', {
...tableOptions,
pageLoaded: (pageNumber) => {
input.value = pageNumber
}
});

Delete a field value based on checkbox-Netsuite

I have a requirement where if the user unchecks the checkbox the vale of certain field should be cleared while he saves it.
To be printed is a checkbox
Check # is field.
If the user unchecks the "To be Printed" checkbox the check # field should be clear while he saves the page.
This should be a user event and will be it be after submit funtion?
How do i achieve this?
Here you have two options to deal with your requirement.
1) You can write a Client script as #John mentioned above on his comment and on field change you can clear out those field values which you don't want to save upon your form submission.
2) Write a before submit function and validate the checkbox field value, if it is unchecked then clear out those fields, which you don't want to save.
I would recommend using user event before submit script to set field value as null, as client script may not fire if data entry point is through csv import, suitescript, etc.
if (nlapiGetFieldValue(TO_BE_SUBMITTED_FIELD_ID) == 'F'){
nlapiSetFieldValue('tranid', null);`
}
If you wish, You may write additional client script to disable/clear the field if value of checkbox is set to false, for better UX.
For sequence number I would say, use the below code (I am assuming sequence numbers are pure numbers)
if (nlapiGetFieldValue(TO_BE_SUBMITTED_FIELD_ID) == 'T'){
//search in descending order (use this code in your same before submit script)
var search = nlapiCreateSearch(RECORD_TYPE, ['mainline', 'is', 'T'], new nlobjSearchColumn('tranid').setSort(true));
var results = search.runSearch();
var records = results.getResults(0, 1);
var nextTranId = praseInt(records[0].getFieldValue('tranid'), 10) + 1;
nlapiSetFieldValue(tranid, nextTranId);
}

fieldChanged function in netsuite

Field Changed Function
If the value in a text field is changed to the same value (example: old value = "ABC", new value = "ABC"), will the script
Field Changed Function fire or not?
nlapiSetFieldValue
Some additional information:
FieldName:
String - the name of the field being set
value: String - the value the field is being set to
firefieldchanged: Boolen - if true then the fieldchange script for
that field is executed. (Only available in Client SuiteScript)
Sets the value of the given field.
This API can be used during beforeLoad scripts to initialize field scripts on new records or non-stored fields.
nlapiSetFieldValue is available only in Client and User Event SuiteScripts.
Whenever you are changing the value of an textfield, you will call the fieldChanged event even if you are staying with the same name as you had before.
If you are asking about the Client Side script event Field Change, if I recall correctly this will only trigger when the user has changed the value of the field in the UI. But this event can also be triggered by the nlapiSetFieldValue and nlapiSetCurrentLineItemValue if the fireFieldChange parameter is set to True.

Resources