Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Custom function in Include file

I know you can have sub routines in an Include file such as...

sub something(param1, param2)

  ...qlikview code

end sub

Can you put a custom function in an Include file such as...

function GetSP(DocLibrary, DocName)

    Let vTitle = Title;

    Let vLeafName = LeafName;

    Tab1:

       load max(TimeLastWritten) as MAXTimeLastWritten

       from X:\TSollenberger\_QVDs\Layer1\PRD_SP_DocumentInfo.qvd (qvd)

         where tp_Title = '$(vDocLibrary)'

         and LeafName = '$(vDocName)';

    LET v_MAXTimeLastWritten = Date(peek('MAXTimeLastWritten'), '$(TimestampFormat)');

    GetSP = vMAXTimeLastWritten

end function

Thanks in advance for any assistance.

3 Replies
consenit
Partner - Creator II
Partner - Creator II

Hi there.

As far as I know there are no user-defined functions in the script, only subroutines.

You can, however, define your functions in a macro module and call them from your script.

Kind regards,

Rrnesto.

marcus_malinow
Partner - Specialist III
Partner - Specialist III

As Ernesto mentions, functions can be written as macros, however I personally try to avoid macros. One way to achieve something similar might be to write a subroutine, and use it to set a variable. This can then be used in your script.

Clever_Anjos
Employee
Employee

Easy way is using a Sub, as you are used to setting a variable

Sub GetSP(DocLibrary, DocName)

    Let vTitle = Title;

    Let vLeafName = LeafName;

    Tab1:

       load max(TimeLastWritten) as MAXTimeLastWritten

       from X:\TSollenberger\_QVDs\Layer1\PRD_SP_DocumentInfo.qvd (qvd)

         where tp_Title = '$(vDocLibrary)'

         and LeafName = '$(vDocName)';

    LET v_MAXTimeLastWritten = Date(peek('MAXTimeLastWritten'), '$(TimestampFormat)');

    LET vGetSPReturn = vMAXTimeLastWritten

end Sub