Qlik Community

QlikView Documents

Documents for QlikView related information.

QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.

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

New Contributor II

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 = +BList;

    if (BList === Parent){



  else if (BList<Parent && BList>MinClose){

  MinClose = BList;



  else if (BList > Parent && BList < MaxClose) {               

  MaxClose = BList ;   



  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;





Resident XXX;

Version history
Revision #:
1 of 1
Last update:
‎02-02-2017 08:34 AM
Updated by: