3 Replies Latest reply: Nov 21, 2017 4:54 AM by Jesus Pita Merino RSS

    C# QMS API Copy a task. Trigger problems

    Gero Kindling


      I am trying to copy an existing task onto another source document. This works very well but there is one thing which should not be there.


      Everything copies fine and the new task looks great. But if I look at the "source" task, which I originally copied, the trigger section is completely empty. All triggers which where there have been removed from the original task but on the new copied task the triggers are there. It's like they did not get copied, they got moved...


      Here is my code by now:


                  // Get properties from the task which should be copied

                  DocumentTask TaskToCopy = Client.GetDocumentTask(taskToCopyId, DocumentTaskScope.All);


                  // Create new document task

                  DocumentTask documentTask = new DocumentTask();


                  // Assign all properties to the new task

                  documentTask = TaskToCopy;


                  // Set task informations

                  documentTask.ID = new Guid();

                  documentTask.QDSID = serviceId;

                  documentTask.Document = sourceDocument;


                  documentTask.General.Enabled = false;

                  documentTask.General.TaskName = taskName;

                  documentTask.General.TaskDescription = "";


                  documentTask.Reload.ScriptParameterName = parameterName;

                  documentTask.Reload.ScriptParameterValue = parameterValue + ";";


                  string targetFileName = reducedDocumentName.Replace("%CustomerName%", customerName.ToLower());

                  targetFileName = targetFileName.Replace("%CustomerId%", customerId);

                  documentTask.Reduce.DocumentNameTemplate = targetFileName;



                  // Save and create the task




      Any help is appreciated.

        • Re: C# QMS API Copy a task. Trigger problems
          Gero Kindling

          I found the answer by myself. I'll post it here so it maybe helps someone running into the same problem.

          Each task has it's own ID (Guid) and as everybody knows, IDs are unique.


          I guess the QlikView server is thinking something equal to this: "What the hell are you doing there? You can't copy/create triggers with an existing ID... I'll better delete the existing triggers with that ID"


          So all what you see, is nothing... No error message anywhere.


          As a workaround for this problem, here is the solution:

          You need to generate a new ID for each existing trigger.


                      // Get all existing triggers from document

                      Trigger[] taskTrigger = documentTask.Triggering.Triggers;


                      // Generate a new ID for each trigger found

                      foreach (Trigger trigger in taskTrigger)


                          trigger.ID = new Guid();




          Hope it helps someone.