Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Select values in a Field using Extension

Hi ,


I am trying to do some selection using Extension object , lets say i have 3 fields age , sex and race i just want to make selection to these field using  Javascript API but  i not able to find one ( i should have been simple )

Lets say i have 3 ages 24,25,46  in an array
ie

var age=[24,25,49];
var sex='Male';
var race='Asian';

i want to select these values to their respective fields in extension code .

Any ideas how it can be achieved ?

Regards,

s_tushar

7 Replies
Nicole-Smith

You want the SelectTextsInColumn() function in your javascript.  Information about this function can be found here: JsDoc Reference - Qv.Document.Object.Data

Not applicable
Author

Hi Nicole ,

     Thanks for the replies.

     What i want to do in my code is that i have a String with this format :  FieldName:Fieldvalue1,fieldValue2,FieldValue3;

Example
var string = "sex:Male,female ;race:asian,african;american ";


//Javscript string handling code for Each Field name pick its Field value

// Qlikview Code within that loop which will apply selection for each field   <-- this is what i am looking into right now .

Not applicable
Author

Hi Nicole ,

     Thanks for the replies.

     What i want to do in my code is that i have a String with this format :  FieldName:Fieldvalue1,fieldValue2,FieldValue3;

Example
var string = "gender:Male,female ;race:asian,african;american ";


//Javscript string handling code for Each Field name pick its Field value

// Qlikview Code within that loop which will apply selection for each field   <-- this is what i am looking into right now

Nicole-Smith

Use Javascript to put your records into an array, and then pass the array into the QV function.

//Use Javascript to get an array with your values -- you can write some code here to get this

var raceRecords = ["asian", "african", "american"];

//Then pass into QlikView

this.Data.SelectTextsInColumn(0, false, raceRecords);

More info on the QV function, so you know what to set your parameters to:

{void}SelectTextsInColumn(Column, toggle, recordsToSelect)

Note! Only available for Extensions.
Selects the visible textrecords in an Extension. Each record you want to select is sent as a parameter to the function - infinite number of parameters are accepted - OR include the records in an array and pass in the array. The parameters must match the textrecord exactly. Use search-function if you instead want to select all possible records for a string.

Example: // Multiple parameters this.Data.SelectTextsInColumn(0, false, "George Washington", "Thomas Jefferson"); // Array var arrRecords = ["George Washington", "Thomas Jefferson"]; this.Data.SelectTextsInColumn(0, false, arrRecords);
Parameters:
{colNo}Column
to select in.
{Boolean}toggleOptional
If true, existing selections will be kept (or deselected if selected again).
{Array|String[]}recordsToSelect
Either an array or multiple parameters for each record.
Not applicable
Author

I need to select Multiple Fields also here  ( No of fields will be dynamic )  . Here in the above example we can select only one field ie for 'Race ' field .

Any idea how we can Loop through list of Field apply its selection using FieldValues in an Extension object ?

Nicole-Smith

You can use Javascript to write the loop.  What kind of loop is dependent on what the rest of your code and values end up looking like.  You'll most likely use a for loop.  Information on loops can be found here: JavaScript for Loop

Not applicable
Author

The code which you mentioned

this.Data.SelectTextIsInColumn() ; this code will work only for the Dimension field which we set for the extension
my requirement is to  have a String Format  ie ( FieldName1:Fielvalue1,fieldvalue2 ; FielName2:Fieldvalue1,fieldvalue2)
example    (Fruit : Apple , Peach , Mango ; Vegetable : Potato , Carrot . Spinach )

so from the above string  i need to  Do a Select Field on Fruit Field and Vegetable field respectively .

I have written a code to loop through the string pick of the FieldName & FieldValue within the loop

Below is the code

  var currentSelectionQv =_this.Layout.Text0.text;  // This will be the String containg the fieldname and fieldvalues i mentioed above

   //  alert('Value from Expression ' + currentSelectionQv);

                var arrSelectionLines = currentSelectionQv.split(lineDelimiter);

           

                if (arrSelectionLines.length > 0 && arrSelectionLines[0] != '-') {

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

                        var line = arrSelectionLines;

                        var tagPos = line.indexOf(tagDelimiter);

                        var fieldName = line.substr(0, tagPos);

                     

                        var fieldValues = line.substr(tagPos + 1, line.length - tagPos).split(valueDelimiter);

        //Here i have the field name            

  alert(fieldName); // Selected Field Name

                        // to add dimension:

   // Here i have its selected values

  alert(fieldValues); //Select Field Value

// I need a code to basically Select the field within this loop

                 

                    }