Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
emotyp101
Partner - Contributor II
Partner - Contributor II

C# QMS API Copy a task. Trigger problems

Hello,

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

            Client.SaveDocumentTask(documentTask);

Any help is appreciated.

1 Solution

Accepted Solutions
emotyp101
Partner - Contributor II
Partner - Contributor II
Author

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.

View solution in original post

3 Replies
emotyp101
Partner - Contributor II
Partner - Contributor II
Author

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.

Anonymous
Not applicable

Gero

Thanks for following up on your original post with your valuable info. It's great to use the forum resource when interesting questions have valuable responses.

I know this will be useful to me in the next few weeks as we start a new similar project.

Anonymous
Not applicable

Hi Gero,

Really interesting code, thanks!

Just one question: Have you tried to copy a task onto another source document but the destination document is located in a different publisher?

I'm trying to do this but at this moment I'm unable to do the copy. All the publishers are visible each other and I can do the copy using the remote management service but it must be done using the QMS API.

Any ideas?

Thanks in advance!!