Author Topic: How to Create a Function  (Read 394 times)

Offline jeisma

  • Associate
  • **
  • Join Date: Dec 2017
  • Posts: 2
  • Forum Citizenship: +0/-0
How to Create a Function
« on: 08 Dec 2017 01:05:53 pm »
Hi,

How do you create a function that you can call inside the Query Explorer's Data Items.

For example, I want to create a function (never mind the syntax just yet)

Code: [Select]
function validDate (invoicedate)
  var validDateFr, validDateTo

  if (inRange(..))
    return true

  return false.
end function

So a Data Item's expression definition, I could have something like this:
Code: [Select]
  if (validDate(current_date)) then
    "OK"
  else "NOT OK"

Possible to do?


TIA!

Offline CognosPaul

  • Global Moderator
  • Statesman
  • *****
  • Join Date: Jan 2009
  • Posts: 1,638
  • Forum Citizenship: +250/-1
    • Paul's Cognos Blog
Re: How to Create a Function
« Reply #1 on: 08 Dec 2017 02:47:43 pm »
Most databases will allow you to create User Defined Functions (UDFs) that you can import into Cognos, and then use like any other function.

SQL Server:
https://docs.microsoft.com/en-us/sql/relational-databases/user-defined-functions/create-user-defined-functions-database-engine

Oracle:
https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions231.htm

Once you create the function, you can use the import wizard in Framework Manager to import it. There should be an expandable functions list.

Offline jeisma

  • Associate
  • **
  • Join Date: Dec 2017
  • Posts: 2
  • Forum Citizenship: +0/-0
Re: How to Create a Function
« Reply #2 on: 08 Dec 2017 02:56:10 pm »

I see, so it's not as simple as I initially thought.  :(

Thank you for taking the time to respond. I'll explore this option.

Offline dougp

  • Statesman
  • ******
  • Join Date: Jul 2014
  • Posts: 272
  • Forum Citizenship: +14/-1
Re: How to Create a Function
« Reply #3 on: 08 Dec 2017 05:14:42 pm »
You may be able to do this with a Cognos macro, although the macro feature is pretty limited.
« Last Edit: 08 Dec 2017 05:28:07 pm by dougp »

Offline dougp

  • Statesman
  • ******
  • Join Date: Jul 2014
  • Posts: 272
  • Forum Citizenship: +14/-1
Re: How to Create a Function
« Reply #4 on: 08 Dec 2017 05:34:36 pm »
Are you sure you need a function?  How about just a data item?

Code: [Select]
if ([invoicedate] between ?validDateFr? and ?validDateTo?)
then ('OK')
else ('Not OK')

 


       
Twittear