Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to programatically make selections

Hi,

In a mashup scenario, I'm aware that you can use code such as this to get the current selections:

app.getList("CurrentSelections", function(reply){


});


What I want to do is set (or make) some selections programatically.


Let's say I have a simple app with a dimension of 'Country' and measure 'Population'.  I wish to automatically set the selections on a bar chart to 'China' and 'India' when the app opens.


Can this be done?  I've spent a long time examining the API(s), but haven't found anything.


Many thanks for any guidance on this!

Shane.

12 Replies
Not applicable
Author

The first country in my list is Afghanistan, and it's ID is 71.  If I pass this value into the .select method, it gets selected.

When I say 'ID', I mean a qElemNumber value of 71.  I can't access this from the 'app.getList' call for current selections. I can see it in a visualisation I've created, but for this situation, I need to get it from the mashup API.

Not applicable
Author

Here's a fuller code sample where I tackled a similar problem:

            $.each(yearList, function (key, value)

            {

                dummy = parseInt(value[0].qText);

                yearMin = yearMin < dummy ? yearMin : dummy;

                yearMax = yearMax > dummy ? yearMax : dummy;

                temp[value[0].qElemNumber] = parseInt(value[0].qText);

            });

            $("#country-comparison-chart-slider").slider({

                range: true,

                min: yearMin,

                max: yearMax,

                step: 1,

                values: [yearMin, yearMax],

                slide: function (event, ui)

                {

                    $("#country-comparison-years").html(ui.values[0] + " to " + ui.values[1]);

                },

                stop: function (event, ui)

                {

                    $("#country-comparison-years").html(ui.values[0] + " to " + ui.values[1]);

                    var selection = [];

                    for (i = 0; i < temp.length; ++i)

                    {

                        if (temp >= ui.values[0] && temp <= ui.values[1])

                        {

                            selection.push(i);

                        }

                    }

                    app.field("Year").select(selection, false,false);

                }

            });

Not applicable
Author

That makes sense, but when I do the equivalent of

app.field("My country name").selectMatch("India", false);

app.field("My country name").selectMatch("China", false);

the resulting state is that only 'China' is selected.  The state isn't accumulated, rather set as an exclusive state for each call.