Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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.
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.
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.
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!!