COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: MrKlar on 01 Oct 2024 08:31:43 AM

Title: Macro Functions: Convert CSVIdentityNameList() to array
Post by: MrKlar on 01 Oct 2024 08:31:43 AM
Hi there,

CSVIdentityNameList() gives me back comma separated values. How do you convert that into a macro to be able to make use of grep() function to be able to search for a certain value?

Thank you very much.
Title: Re: Macro Functions: Convert CSVIdentityNameList() to array
Post by: MFGF on 01 Oct 2024 09:26:23 AM
Quote from: MrKlar on 01 Oct 2024 08:31:43 AMHi there,

CSVIdentityNameList() gives me back comma separated values. How do you convert that into a macro to be able to make use of grep() function to be able to search for a certain value?

Thank you very much.

Hi,

CSVIdentityNameList() is a macro function - you can only use it in a macro. Anything within hashes is classed as a macro, so #CSVIdentityNameList()# is a very short macro that returns your comma delimited list of account name, groups and roles. You can use any other macro syntax within the hashes, also, so you could add in your grep command

#
join('',
grep('System Admin',CSVIdentityNameList())
)
#

Not sure what you're trying to achieve? CSVIdentityNameList() returns an array of strings, which may or may not be what you need?

Cheers!

MF.
Title: Re: Macro Functions: Convert CSVIdentityNameList() to array
Post by: MrKlar on 01 Oct 2024 09:41:23 AM
Quote from: MFGF on 01 Oct 2024 09:26:23 AMjoin('',
grep('System Admin',CSVIdentityNameList())
)
#

MF.

Hi MF, thank your for the quick reply.

However, if I use your above macro code, I get the following error:
Argument type 2 of function 'grep' is: string, but the required type is: array.

That is why I was posting the question, wondering what data type CSVIdentityNameList() actually returns.

However with a split function inbetween and douple pipes (||) the conversion to an array seems to work, at least for me:

# join(','; grep('System Admin'; split('||';CSVIdentityNameList('||')) ) ) #