Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

QMSAPI Add user to Document Calc

Hi,

I have a problem with adding user document calc to my documents.

I use this code below. It says at the SaveDocumentMetaData that there are too many document calcs assigned even though i cannot see any assignments in QMC. I have also tried with code which deletes the user. And i have tried getting a list of assigned users. And the user is not assigned.

static void AddCAL()

        {

            QMSClient Client;

            string QMS = "http://localhost:4799/QMS/Service";

            Client = new QMSClient("BasicHttpBinding_IQMS", QMS);

            string key = Client.GetTimeLimitedServiceKey();

            ServiceKeyClientMessageInspector.ServiceKey = key;

            ServiceInfo[] MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);

            DocumentNode[] allDocs = Client.GetUserDocuments(MyQVS[0].ID);

            DocumentMetaData Meta;

            //Client.ClearQVSCache(QVSCacheObjects.UserDocumentList); //Clears chaching

            //Create a couple of strings to hold the name of the QVW we want to work with and the name of the user to add a CAL for.

            string document = "Report_78390761-CB65-4669-BAAF-5A7BFADA25EE.qvw";

            string user = "DOMAIN\\qvide";

            //There is not a "Find document" function in the API and so we need to loop through the DocumentNode array to find the file we want to use.

            //Once we find it, we extract its meta data and its list of assigned CALs as before. 

            //Now we create a new AssignedNamedCAL and add the name of the user to it. 

            //This new object is added to the existing list, pushed back into the meta data and finally the new data is saved back to the server.

            for (int i = 0; i < allDocs.Length; i++)

            {

                if (allDocs.Name == document)  //If the document matches the one im looking for then apply the changes

                {

                    //Get the meta data for the current document

                    Meta = Client.GetDocumentMetaData(allDocs, DocumentMetaDataScope.Licensing);

                    //Extract the current list of Document CALs

                    //CALConfiguration myCalcs = Client.GetCALConfiguration(MyQVS[0].ID,CALConfigurationScope.DocumentCALs);

                    List<AssignedNamedCAL> currentCALs = Meta.Licensing.AssignedCALs.ToList();

                    //Create a new CAL object and set the username for it

                    AssignedNamedCAL newCAL = new AssignedNamedCAL();

                    newCAL.UserName = user;

                    //Add the new cal to the list of CALs object

                    currentCALs.Add(newCAL);

                    //Add the updated CALs list back to the meta data object

                    Meta.Licensing.AssignedCALs = currentCALs.ToArray();

                    //Save the metadata back to the server

                    Client.SaveDocumentMetaData(Meta);

                    //Client.SaveCALConfiguration(myCalcs);

                }

            }

Does anyone have experience in this?

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

Please see this url for info about user management API

braathen/qv-user-manager · GitHub

View solution in original post

1 Reply
Not applicable
Author

Hi,

Please see this url for info about user management API

braathen/qv-user-manager · GitHub