Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

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.

Tags (1)
3 Replies
consenit
Contributor II

Re: Custom function in Include file

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
Valued Contributor III

Re: Custom function in Include file

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.

Employee
Employee

Re: Custom function in Include file

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