Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.

Qlik Sense: How to bulk add columns to a straight table with the .NET SDK

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Damien_V
Support
Support

Qlik Sense: How to bulk add columns to a straight table with the .NET SDK

Last Update:

Dec 22, 2022 12:30:18 AM

Updated By:

Damien_V

Created date:

Dec 22, 2022 12:30:18 AM

This article explains how to get started with the .NET SDK

The following must be installed to test the example provided in this article:

  • Microsoft Visual Studio (The community version can be used)
  • Qlik Sense Server


*It does not need to be installed on the same machine, but proper ports must be open for incoming connection on the Qlik Sense server side.

Please also make sure that the user connecting from the .NET SDK has a license assigned

Environments:

Qlik Sense Enterprise any version
 

 

Resolution:

For instructions on how to get started with the .NET SDK, see Qlik Sense: Getting started with the .NET SDK

The sample in this article replaces all columns in the straight table by the one filled inside the "dimname" array.

  1. Open Visual Studio and create a new project. In this example, we have selected "Console App (.NET Framework)"
  2. Paste the following code sample:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Qlik;
using Qlik.Engine;

namespace ConsoleApp1
{
    class AddColumns
    {
        private static NxInlineDimensionDef SetCid(NxInlineDimensionDef dim)
        {
            dim.Set("cId", Guid.NewGuid().ToString());
            return dim;
        }
        static void Main(string[] args)
        {
            Uri uri = new Uri("https://qlikserver1.domain.local/");
            ILocation location = Qlik.Engine.Location.FromUri(uri);
            location.AsNtlmUserViaProxy(certificateValidation: false);
            IAppIdentifier appIdentifier = location.AppWithId("e71b8751-cf48-4fde-ab9e-c58ecce54d75");
            using (var app = location.App(appIdentifier))
            {

                var layout = app.GetAppLayout();
                Console.WriteLine(layout.Title + " [" + app.Type + "]");

                var dimname = new[] { "Dim2", "Dim1", "Dim3", "Dim1", "Dim3" };
                var cube = new HyperCubeDef();
                var dimensions = Enumerable.Range(0, dimname.Length).Select(n => SetCid(new NxInlineDimensionDef { FieldDefs = new[] { dimname[n] } }));
                cube.Dimensions = dimensions.Select(dim => new NxDimension { Def = dim }).ToArray();
                cube.Set("columnWidths", Enumerable.Range(0, dimname.Length).Select(_ => -1).ToArray());

                var tableObjectId = "CEPcZ";
                var o = app.GetGenericObject(tableObjectId);
                using (o.SuspendedLayout)
                {
                    o.Properties.Set("qHyperCubeDef", cube);
                }

                app.DoSave();

                Console.ReadLine();
            }
        }
    }
}

 

Following lines need to be updated with:

Your Qlik Sense server name

Uri uri = new Uri("https://qlikserver1.domain.local/");

The app ID

IAppIdentifier appIdentifier = location.AppWithId("e71b8751-cf48-4fde-ab9e-c58ecce54d75");

The list of dimensions to be added to the table:

var dimname = new[] { "Dim2", "Dim1", "Dim3", "Dim1", "Dim3" };

The straight table object ID

var tableObjectId = "CEPcZ";


Result:
Test1 [Doc]


Tip: If the program does not run, try to build it and execute the .exe file from the Qlik Sense server. If that works locally from the server itself, it might be that there is a network device that is not allowing the connection or the proper ports are not open.

Labels (1)
Contributors
Version history
Last update:
‎2022-12-22 12:30 AM
Updated by: