
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to create User-Defined function and call it?
Hi, I would like to create a function to scramble a few fields. A few questions:
1. Should I use Sub for Function key word? See below example, which don't have detailed logic.
Sub Scramble (field)
Scramble = UCase(field)
End Sub;
2. Can this function be placed in a block within the script editor?
3. How do I call this function? I called this function using below script, but it failed. Any suggestions?
Scramble(ContactName) AS Name
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's fine using variable for simple algorithm, but what about more complex logic is required.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have to scramble the text string in the SQL function, but would really like to know how to create and call function in Qlik.
A simple working example is most helpful. I am struggling to find such a sample, as there is very limited resources on web.
Thanks for your time!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
You can set a dynamic variable. For example;
Set vFirstXLetters = mid($1,1,len($2))
After you declare this variable in script editor, you can use this variable like any function.
=$(vFirstXLetters('qliksense',1,'qlik') this will return 'qlik' as a result.
And you can use this variable in script editor.
set vOmitLetters = mid($1,len($2)+1,len($1));
load
*,
$(vOmitLetters(country,prefix)) as CountriesWithoutPrefix
inline
[
country, prefix
germany,ger
england,eng
sweden,swe
]
I know the example is pretty much simple but it should be your starting point.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's fine using variable for simple algorithm, but what about more complex logic is required.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the answer. However, how can I set up a function in the editor (like yours vFirstXLetters) and then repeatedly use this function in tables and charts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Sorry for late answer. Adding .qvf file to check how to use custom functions on your tables and charts.
