Click or drag to resize
IQMSAddSelections Method
Adds or toggles the currently selected fields within a document.

Namespace: PIX.Services.V12
Assembly: 
Syntax
List<FieldContent> AddSelections(
	QDSDocumentSession session,
	List<FieldContent> fieldContents,
	bool lockSelection,
	bool toggleSelect,
	bool returnSelectedList
)

Parameters

session
Type: PIX.QMSAPI.DataObjectsQDSDocumentSession
The session to be used.
fieldContents
Type: System.Collections.GenericListFieldContent
The selected fields to add or toggle
lockSelection
Type: SystemBoolean
Set this to true if you want to lock the selected fields.
toggleSelect
Type: SystemBoolean
If set to true, toggles to selected fields, otherwise sets them to be selected in the document.
returnSelectedList
Type: SystemBoolean
Set to true if a list of currently selected fields should be returned.

Return Value

Type: ListFieldContent
A list of selected fields.
Remarks
Security note Security Note

Requires membership of local group QlikView Management API and the role Document Folder Administrator.

Examples
This example assumes that the document used contains a Quarter field which is related to a Month field. It retrieves all the values from the Quarter field and adds a new selection using the first value. Next it retrieves the values from the Month field and prints them to the console. Here it is possible to see which of the months that were selected or excluded after the quarter selection.

The service key injection is assumed to be handled behind the scenes. For an example of how to inject the service key, see Samples.

C#
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading;
 using QMSAPI;

class Program
{
     static void Main(string[] args)
     {
         try
         {
             // create a QMS API client
             IQMS apiClient = new QMSClient();

             //retrieve a time limited service key
             ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey();

             ServiceInfo serviceInfo = apiClient.GetServices(ServiceTypes.QlikViewDistributionService).FirstOrDefault();
             if (serviceInfo != null)
             {
                 QDSDocumentSessionConfiguration sessionConfig = new QDSDocumentSessionConfiguration();

                 sessionConfig.QDSID = serviceInfo.ID;
                 sessionConfig.FilePath = @"C:\ProgramData\QlikTech\SourceDocuments\Sales.qvw";

                 QDSDocumentSession documentSession = apiClient.CreateSession(sessionConfig);

                 if (documentSession != null && documentSession.OpenDocumentResult == DocumentState.OpenedSuccessfully)
                 {
                     List<FieldContent> fieldContentList = apiClient.GetFieldContentList(documentSession, "Quarter", FieldContentType.All, 0, 4);
                     FieldContent firstField = fieldContentList.FirstOrDefault();
                     if(firstField != null)
                     {
                         //Remove all fields but the first one and add it as a selection.
                         firstField.Values.RemoveRange(1, firstField.Values.Count - 1);
                         apiClient.AddSelections(documentSession, new List<FieldContent>(){firstField}, false, false, true );

                         //Retrieve all the contents of the Month field.
                         FieldContent monthField = apiClient.GetFieldContentList(documentSession, "Month", FieldContentType.All, 0, 12).FirstOrDefault();

                         if (monthField != null) {

                             Console.WriteLine(monthField.Name);

                             //Print all the values for the month field.
                             foreach(FieldValue fv in monthField.Values )
                             {
                                 Console.WriteLine(string.Format("{0} {1}", fv.IsNumeric ? fv.Number.ToString() : fv.Text, fv.State ));
                             }
                         }
                         apiClient.CloseSession(documentSession);
                     }
                 }
                 else
                 {
                     Console.WriteLine("Failed to open the document.");
                 }
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine("An exception occurred: " + ex.Message);
         }
         // wait for user to press any key
         Console.ReadLine();
     }
 }
See Also