How to create Java Script Function and passing array from load script

    I often use a function that usually shortnes my loading proccess


    This is step by step guide that explain how to create and using Java Script function in edit script load data.


    In the example below the function will return the serching number if is exist in an array list, else, the smaller closet number returned , else, if not exist smaller closer number the big closet returned.


    Set enable to call function from load script

    HELP>About Qlikview>right click on QV icon

    Change AllowMacroFunctionslnExpression to "1"


    Then open Edit Modul (ctrl+m) and past the following script


    function FindBL(BList,Parent){

      var MinClose=0;

      var MaxClose=100;

      var Equel=0;

      var BL_FINAL=0;

        BList= BList.split(',');

        for (var i=0; i<BList.length; i++){

            BList[i] = +BList[i];

        if (BList[i] === Parent){



      else if (BList[i]<Parent && BList[i]>MinClose){

      MinClose = BList[i];



      else if (BList[i] > Parent && BList[i] < MaxClose) {               

      MaxClose = BList[i] ;   



      if (Equel !==0) {

       BL_FINAL = Equel;


      else if (MinClose !==0) {

      BL_FINAL = MinClose;


      else if (MaxClose !==100 ){

      BL_FINAL = MaxClose;


         return BL_FINAL;





    In load script write the following line and click on load button :

    SET A= FindBL('3,4,7,8,10','9');


    If you wish to using in resident data

    use the following script




         Replace(chr(39)&concat(DISTINCT BLIST&',')&chr(39),','&chr(39),chr(39)) AS BL_CL 

    Resident XX;

    LET vBLs = peek('BL_CL');

    DROP Table temp_tbl;





    FindBL($(vBLs),X)  AS BL_CL_FINAL

    Resident XXX;