25 Replies Latest reply: Nov 7, 2014 9:51 AM by Ryan Kempey RSS

    QMS API Creating a new task

    Daniel Rozental

      I can't seem to be able to set the name on the new task, task gets created with default name.

       

      Here's my code, any ideas are welcome.

       

      Dim QMSClient As New QMSBackendClient()
      Dim QvsId As Guid
      'Gets the request Key when the page is loaded
      ServiceKeyClientMessageInspector.ServiceKey = QMSClient.GetTimeLimitedServiceKey()
      
      'Fetching the ID of the first QVS resource
      Dim qvsServices As QVPublisher.QMSBackendService.ServiceInfo()
      qvsServices = QMSClient.GetServices(ServiceTypes.QlikViewDistributionService)
      QvsId = New Guid(qvsServices(0).ID.ToString())
      
      Dim qvDocs As QVPublisher.QMSBackendService.DocumentNode()
      qvDocs = QMSClient.GetSourceDocuments(QvsId) 
      
      Dim qvDocTasks As New QVPublisher.QMSBackendService.DocumentTask
      
      qvDocTasks.QDSID = QvsId
      qvDocTasks.Document = qvDocs(1)
      
      qvDocTasks.DocumentInfo = New QVPublisher.QMSBackendService.DocumentTask.TaskDocumentInfo
      qvDocTasks.Distribute = New QVPublisher.QMSBackendService.DocumentTask.TaskDistribute
      qvDocTasks.Reduce = New QVPublisher.QMSBackendService.DocumentTask.TaskReduce
      qvDocTasks.Reload = New QVPublisher.QMSBackendService.DocumentTask.TaskReload
      
      qvDocTasks.General = New QVPublisher.QMSBackendService.DocumentTask.TaskGeneral
      qvDocTasks.General.TaskName = "API TEST"
      qvDocTasks.General.Enabled = False
      
      qvDocTasks.Triggering = New QVPublisher.QMSBackendService.DocumentTask.TaskTriggering
      
      QMSClient.SaveDocumentTask(qvDocTasks)
      
      
        • QMS API Creating a new task
          Joe Bickley

          Im seeing the same thing.

           

          I have noticed that if i set a GUID for the task then the task name is set as "Default" but if i leave the guid out then the task name is set as "reload of \\pathtodoc\app.qvw"

           

          So it seems that there might be an extra setting to apply to get it to ignore these defaults.

          • Re: QMS API Creating a new task
            Bas Knol

            Hi,

             

            You might want to try the following:

             

            Set the property 'Scope' on the object DocumentTask. You can set the scope using DocumentTaskScope.

            For example: if you want to set values on the general-tab and reload-tab of a task use:

             

            C# example

            documentTask.Scope = DocumentTaskScope.General | DocumentTaskScope.Reload;
            

             

            Example code for creating a task in C#:

             

                        QMSBackendClient qmsClient = new QMSBackendClient();
                        DocumentTask documentTask = new DocumentTask(); 
            
                        //Set time limited service key
                        ServiceKeyClientMessageInspector.ServiceKey = qmsClient.GetTimeLimitedServiceKey(); 
            
                        //Get QDS guid
                        List<ServiceInfo> serviceList = qmsClient.GetServices(ServiceTypes.QlikViewDistributionService);
                        Guid qdsGuid = serviceList[0].ID; 
            
                        //Get source documents
                        List<DocumentNode> sourceDocuments = qmsClient.GetSourceDocuments(qdsGuid); 
            
                        documentTask.QDSID = qdsGuid;
                        documentTask.Document = sourceDocuments[0]; //Get first source document for this example
                        documentTask.General = new DocumentTask.TaskGeneral();
                        documentTask.General.Enabled = true;
                        documentTask.General.TaskName = "Task1";
                        documentTask.General.TaskDescription = "Creating a task via QMS API";
                        documentTask.Scope = DocumentTaskScope.General;
            
                        //Create task            
                        qmsClient.SaveDocumentTask(documentTask);
            
            

             

            I was able to succesfully create a task with the specified task name uing the scope property.

            A default task name is set when I do not use the scope property.

             

            Hope this helps!

              • Re: QMS API Creating a new task
                Daniel Rozental

                Awesome, right on the money.

                 

                Thanks Bas.

                  • QMS API Creating a new task
                    Joe Bickley

                    Not go to test this just yet but im pretty sure you are right based on another conversation.

                     

                    There are a few oddities with other areas the API requiring you to set some values you dont expect for it to work as expected.

                     

                    Im going to see if i can start a blog to push out some samples that will hopefully show up on google searches!

                      • Re: QMS API Creating a new task

                        Hi,

                         

                        In your example did you try to add the triggers, document info using QMS API ? If yes can you tell me how did you do it ?

                         

                        I have written following code but it is not working -

                         

                                        documentTask.General = new DocumentTask.TaskGeneral();

                                        documentTask.General.Enabled = true;

                                        documentTask.General.TaskName = "Task123";

                                        documentTask.General.TaskDescription = "Creating a task via QMS API";

                         

                                        documentTask.DocumentInfo = new DocumentTask.TaskDocumentInfo();

                                        documentTask.DocumentInfo.Category = "Parallel_Test";

                                        documentTask.DocumentInfo.Description = "Task created using QMS API";

                         

                                        Guid triggerID = new Guid("e95ecd5a-683d-1d33-26bf-66e94ff08223");

                                       

                                        Trigger t = new Trigger();

                                        List<Trigger> List_Trigger = new List<Trigger>();

                                        t.Type = TaskTriggerType.OnceTrigger;

                                        t.Enabled = true;

                                        t.ID = triggerID;

                                        List_Trigger.Add(t);

                         

                                        documentTask.Triggering = new DocumentTask.TaskTriggering();

                                        documentTask.Triggering.Triggers = List_Trigger;

                                                                                    

                                        documentTask.Scope = DocumentTaskScope.General;

                                        apiClient.SaveDocumentTask(documentTask);

                         

                        After executing this code, I am able to see the Task123 in QEMC, but it has no triggers and no document information.

                         

                        Regards,

                        Samir Prasadi

                          • Re: QMS API Creating a new task
                            Joe Bickley

                            Prasadi - do you only have QlikView Server in your case and NOT publisher?

                             

                            Im trying to resolve a similar issue where the code works fine if i have publisher licensed but if i dont then it creates the task without any triggers.

                            • Re: QMS API Creating a new task
                              Bas Knol

                              You have set the document scope to:

                               

                              documentTask.Scope = DocumentTaskScope.General;

                               

                              QMS API will only look for the DocumentTask.TaskGeneral object because you have defined this in the scope property.

                               

                              Try to change the document task scope line to this:

                               

                              documentTask.Scope = DocumentTaskScope.General | DocumentTaskScope.DocumentInfo | DocumentTaskScope.Triggering;
                              

                               

                              This should work.

                                • Re: QMS API Creating a new task

                                  Yes I identified this. Thanks for the quick response

                                   

                                  Regards,

                                  Samir

                                  • Re: QMS API Creating a new task

                                    Hi,

                                     

                                    I have one more question. When I add the scope DocumentTaskScope.Triggering it becomes mandatory to set the properties of Task dependency. Is there any work around for this ?

                                     

                                    I am using following code to trigger the task but it is not working properly -

                                     

                                                    Guid triggerID = new Guid("6eaf55f8-6737-48b5-b4d5-85f8a235ccb3");

                                                    //Guid triggerID = Guid.NewGuid();

                                                   

                                                    // Create a scheduled trigger

                                                    ScheduleTrigger st = new ScheduleTrigger();

                                                    st.ID = triggerID;

                                                    st.Type = TaskTriggerType.OnceTrigger;

                                                    st.Enabled = true;

                                                    st.StartAt = DateTime.Now;

                                     

                                                    // Create a list of trigger and add the scheduled trigger

                                                    List<Trigger> List_Trigger = new List<Trigger>();

                                                    List_Trigger.Add(st);

                                                   

                                                    /*

                                                    Trigger t = new Trigger();

                                                    List<Trigger> List_Trigger = new List<Trigger>();

                                                    t.Type = TaskTriggerType.OnceTrigger;

                                                    t.Enabled = true;

                                                    t.ID = triggerID;

                                                    List_Trigger.Add(t);*/

                                     

                                                    documentTask.Triggering = new DocumentTask.TaskTriggering();

                                                    documentTask.Triggering.Triggers = List_Trigger;

                                                   

                                                    // Create list for task dependencies

                                                    List <TaskInfo> taskdep = new List<TaskInfo>();

                                     

                                                    TaskInfo tf = new TaskInfo();

                                                    tf.Enabled = false;

                                                    //tf.QDSID = qdsGuid;

                                                    tf.ID = Guid.NewGuid();

                                                    tf.Type = TaskType.DocumentTask;

                                                    taskdep.Add(tf);

                                     

                                                    documentTask.Triggering.TaskDependencies = taskdep;

                                     

                                                    documentTask.Triggering.ExecutionAttempts = 1;

                                                    documentTask.Triggering.ExecutionTimeout = 0;

                                     

                                                    // Scope plays an important role

                                                    documentTask.Scope = DocumentTaskScope.General | DocumentTaskScope.Triggering;                                     

                                                    //documentTask.Scope = DocumentTaskScope.General | DocumentTaskScope.DocumentInfo;

                                                    //documentTask.Scope = DocumentTaskScope.General | DocumentTaskScope.DocumentInfo | DocumentTaskScope.Triggering;

                                     

                                                    //Create task           

                                                    apiClient.SaveDocumentTask(documentTask);

                                     

                                    The task is getting corrupted and QEMC gives an error.

                                     

                                    Regards,

                                    Samir

                                      • Re: QMS API Creating a new task
                                        Bas Knol

                                        Did you try to pass an empty list?

                                         

                                        Like this:

                                         

                                        documentTask.Triggering.TaskDependencies = new List<TaskInfo>();
                                        

                                         

                                        What error do you get in QEMC?

                                          • Re: QMS API Creating a new task

                                            It is working after passing the empty list .

                                             

                                            Earlier in QEMC the task was getting created with an empty trigger. When I tried to edit it QEMC gave an error saying that it could not load all the tasks.

                                              • Re: QMS API Creating a new task

                                                Hi Bas,

                                                 

                                                Can you help me with the code to distribute the task ? I am using following code -

                                                 

                                                                List<ServiceInfo> QVserviceList = apiClient.GetServices(ServiceTypes.QlikViewServer);

                                                                List<TaskDistributionEntry> List_TaskDist = new List<TaskDistributionEntry>();

                                                                List<DirectoryServiceObject> List_Dir = new List<DirectoryServiceObject>();

                                                 

                                                                DirectoryServiceObject DSO = new DirectoryServiceObject();

                                                                DSO.Type = DirectoryServiceObjectType.Authenticated;

                                                                //DSO.Name = "Root Folder";

                                                                List_Dir.Add(DSO);

                                                               

                                                                TaskDistributionEntry TDE = new TaskDistributionEntry();

                                                                TDE.Destination = new TaskDistributionDestination();

                                                                TDE.Destination.QlikViewServer = new                     TaskDistributionDestination.TaskDistributionDestinationQlikViewServer();

                                                                TDE.Destination.QlikViewServer.ID = QVserviceList[0].ID;

                                                                TDE.Destination.QlikViewServer.Name = QVserviceList[0].Name;

                                                                TDE.Destination.QlikViewServer.Mount = "Root Folder";

                                                                TDE.Destination.Type = TaskDistributionDestinationType.QlikViewServer;

                                                                TDE.Recipients = List_Dir;

                                                 

                                                                List_TaskDist.Add(TDE);

                                                 

                                                                documentTask.Distribute = new DocumentTask.TaskDistribute();

                                                                documentTask.Distribute.Static = new DocumentTask.TaskDistribute.TaskDistributeStatic();

                                                                documentTask.Distribute.Static.DistributionEntries = List_TaskDist;

                                                 

                                                                documentTask.Distribute.Dynamic = new DocumentTask.TaskDistribute.TaskDistributeDynamic();

                                                               

                                                                documentTask.Scope = DocumentTaskScope.General | DocumentTaskScope.DocumentInfo |                DocumentTaskScope.Triggering | DocumentTaskScope.Reload | DocumentTaskScope.Reduce |                DocumentTaskScope.Distribute;

                                                 

                                                However I am getting error -

                                                "There was an error while trying to serialize parameter http://ws.qliktech.com/QMS/11/:documentTask. The InnerException message was 'Enum value '0' is invalid for type 'MyTestApplication.QMSAPI.UserIdentityValueType' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'.  Please see InnerException for more details."

                                                 

                                                Thanks,

                                                Samir

                                                  • Re: QMS API Creating a new task
                                                    Bas Knol

                                                    The exception has probably something to do with the property 'IdentityType' belonging to the the 'TaskDistributeDynamic' object.

                                                     

                                                    Try to set some default values on the TaskDistributeDynamic object:

                                                     

                                                    /// <summary>
                                                    /// Get default object for TaskDistributeDynamic
                                                    /// </summary>
                                                    /// <returns>DocumentTask.TaskDistribute.TaskDistributeDynamic</returns>
                                                    private DocumentTask.TaskDistribute.TaskDistributeDynamic GetTaskDistributeDynamic()
                                                    {
                                                         DocumentTask.TaskDistribute.TaskDistributeDynamic taskDistributeDynamic = new DocumentTask.TaskDistribute.TaskDistributeDynamic();
                                                    
                                                         taskDistributeDynamic.Destinations     = new List<TaskDistributionDestination>();
                                                         taskDistributeDynamic.FieldName       = string.Empty;
                                                         taskDistributeDynamic.IdentityType     = UserIdentityValueType.DisplayName;
                                                    
                                                         return taskDistributeDynamic;
                                                    }
                                                    

                                                     

                                                    The QMS API uses the scope to see if it has to set values (for example) for 'reload' or 'distribute'.
                                                    As far as I know, if you define a task scope QMS API wants that every property for the objects in that task scope are set.

                                                    Otherwise it will give an error. Even if you don't use (in your case TaskDistributeDynamic) for setting up the task.

                                                    Set some default values and it will work. Just create a task in Q(E)MC and see what default values are set.

                                                    The 'TaskDistributeDynamic' object refers to the tab 'Distribute' -> 'Loop Field in Document' that you see in Q(E)MC when you are creating a task.

                                                     

                                                    Hope this helps!

                                                      • Re: QMS API Creating a new task

                                                        Yup. I defined the following property -

                                                         

                                                             documentTask.Distribute.Dynamic.IdentityType = UserIdentityValueType.DisplayName;

                                                         

                                                        and it is working fine now.

                                                         

                                                        Thanks,

                                                        Samir

                                                          • Re: QMS API Creating a new task

                                                            Hi,

                                                             

                                                            I am trying to find an api which gives me list of existing triggers for the given task_id. Are you aware of any such api ? I am not able to find it in QMS API doc.

                                                             

                                                            Thanks,

                                                            Samir.

                                                              • Re: QMS API Creating a new task
                                                                Bas Knol

                                                                Hi Samir,

                                                                 

                                                                Use the function 'GetDocumentTask' and pass your task_id as a parameter and a DocumentTaskScope.

                                                                Use 'DocumentTaskScope.All' to get all data that belong to the task.

                                                                 

                                                                The DocumentTask object has a member 'Triggering' which results in a object DocumentTask.TaskTriggering.

                                                                This object has a member 'Triggers', which is a list of triggers.

                                                                 

                                                                Try to cast a trigger in the list to the correct trigger type, for example ScheduleTrigger, ExternalEventTrigger.

                                                                You could use the 'Type' property of the trigger to check to which trigger object you should cast.

                                                                 

                                                                Good luck!

                                                                  • Re: QMS API Creating a new task

                                                                    Hi,

                                                                     

                                                                    I am using the api GetDocumentTask to get the list of triggers. I am using the following code -

                                                                     

                                                                    documentTask = apiClient.GetDocumentTask(TaskID, DocumentTaskScope.All);

                                                                     

                                                                    // Define the event trigger properties

                                                                    TaskEventTrigger eventTrigger = new TaskEventTrigger();

                                                                    eventTrigger.ID = Guid.NewGuid();

                                                                    eventTrigger.Enabled = true;

                                                                    eventTrigger.TaskID = taskID;

                                                                    eventTrigger.Type = TaskTriggerType.TaskFinishedTrigger;

                                                                     

                                                                    // Create trigger list and add event trigger

                                                                    List<Trigger> listTrigger = new List<Trigger>();

                                                                    listTrigger.Add(eventTrigger);

                                                                     

                                                                    documentTask.Triggering = new DocumentTask.TaskTriggering();

                                                                    documentTask.Triggering.Triggers.Add(eventTrigger);

                                                                    documentTask.Triggering.TaskDependencies = new List<TaskInfo>();

                                                                    documentTask.Triggering.ExecutionAttempts = 1;

                                                                    documentTask.Triggering.ExecutionTimeout = 1440;

                                                                     

                                                                    documentTask.Scope = DocumentTaskScope.Triggering;

                                                                     

                                                                    // Create Trigger

                                                                    apiClient.SaveDocumentTask(documentTask);

                                                                     

                                                                    This code is giving error that the object reference not set to an instance of object at line - documentTask.Triggering.Triggers.Add(eventTrigger);

                                                                     

                                                                    I have a requirement to ADD triggers to the task. My task already has some triggers so I want to append the trigger to the existing list from code. If I use the code -

                                                                     

                                                                    documentTask.Triggering.Triggers = listTrigger;

                                                                     

                                                                    This removes all the triggers which previously existed and just adds the eventTrigger.

                                                                     

                                                                    Can you help me how we can do this ?

                                                                     

                                                                    Thanks,

                                                                    Samir

                                                                    • Re: QMS API Creating a new task
                                                                      Stelios Genouzos

                                                                      Hi bas,

                                                                      I have a similar case,create a task and a trigger for all the available qvw.I followed the above examples but i cant create trigger.I manage to create an empty line(with the edit and delete sign) but without attributes of the trigger(type,start time,etc).

                                                                      Below is my code.

                                                                      Any kind of help will be appreciate!

                                                                       

                                                                       

                                                                      System;


                                                                      System.Collections.Generic;


                                                                      System.Linq;


                                                                      System.Text;


                                                                      QMSAPIStarter.QMSAPIService;


                                                                      QMSAPIStarter.ServiceSupport;




                                                                      QMSAPIStarter



                                                                      class Program



                                                                      static void Main(string[] args)



                                                                      QMSClient Client;


                                                                      string DocName = System.String.Empty;


                                                                      string NewList = System.String.Empty;


                                                                      int i = 0;



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


                                                                      new QMSClient("BasicHttpBinding_IQMS", QMS);


                                                                      string key = Client.GetTimeLimitedServiceKey();


                                                                      ServiceKeyClientMessageInspector.ServiceKey = key;



                                                                      ServiceInfo[] myServices = Client.GetServices(ServiceTypes.All);


                                                                      Guid qdsGuid = myServices[1].ID;



                                                                      //QMSClient qmsClient =Client;


                                                                      DocumentTask documentTask = new DocumentTask();



                                                                      //Get source documents


                                                                      DocumentNode[] sourceDocuments =Client.GetSourceDocuments (qdsGuid);




                                                                      foreach ( DocumentNode Documents in sourceDocuments)






                                                                      //}





                                                                      //documentTask.Document = sourceDocuments[0]; //Get first source document for this example



                                                                      //Console.WriteLine(sourceDocuments[0]);


                                                                      new DocumentTask.TaskGeneral();


                                                                      true;



                                                                      //documentTask.General.DocumentInfo = DocName;


                                                                      // documentTask.Reload.Enabled=true;




                                                                      "Creating a task via QMS API";


                                                                      new DocumentTask.TaskDocumentInfo();



                                                                      "Parallel_Test";



                                                                      "Task created using QMS API";



                                                                      DocumentAttribute _da = new DocumentAttribute();


                                                                      "a";


                                                                      "a";


                                                                      new DocumentAttribute[1];




                                                                      Guid triggerID = new Guid("5b219800-ad7d-477e-83da-3357f84133ff");



                                                                      DocumentTaskScope.General | DocumentTaskScope.DocumentInfo;// | DocumentTaskScope.Triggering;






                                                                      //Create task           









                                                                      //triggerID = Guid.NewGuid();


                                                                      ScheduleTrigger st = new ScheduleTrigger();


                                                                      // triggerID;


                                                                      TaskTriggerType.OnceTrigger;


                                                                      true;


                                                                      DateTime.Now;




                                                                      // Create a list of trigger and add the scheduled trigger


                                                                      //List<Trigger> List_Trigger = new List<Trigger>();


                                                                      //List_Trigger.Add(st);



                                                                      // Create a list of trigger and add the scheduled trigger


                                                                      Trigger[] List_Trigger = new Trigger[1];



                                                                      //List_Trigger[1] = st;



                                                                      new DocumentTask.TaskTriggering();


                                                                      //List_Trigger.ToList();


                                                                      //retval = entityRegistry.Values.OfType<T>().ToList(); 



                                                                      TaskInfo[] _TaskInfoList = new TaskInfo[1];



                                                                      TaskInfo tf = new TaskInfo();


                                                                      false;


                                                                      //tf.QDSID = qdsGuid;


                                                                      Guid.NewGuid();


                                                                      TaskType.DocumentTask;


                                                                      //taskdep.Add(tf);


                                                                      DocumentTaskScope.General | DocumentTaskScope.Triggering;


                                                                       

                                                                      Client.SaveDocumentTask(documentTask);

                                                                       







                                                                • Re: QMS API Creating a new task

                                                                  Thanks for all the info!

                                                                   

                                                                  I have created a task successfully and ran it but while distributing it is not replacing the existing file. Instead it has created a new file. for ex: filename_1.

                                                                   

                                                                  Can you please help.

                                                                    • Re: QMS API Creating a new task

                                                                      Hi srythideva,

                                                                       

                                                                      Make sure your DocumentTask.scope object is completely set. For example:

                                                                       

                                                                      docTask.Scope = DocumentTaskScope.General | DocumentTaskScope.Reload | DocumentTaskScope.DocumentInfo | DocumentTaskScope.Triggering | DocumentTaskScope.Distribute | DocumentTaskScope.Reduce | DocumentTaskScope.Server;

                                                                       

                                                                      All of the properties need to be set as well. I think you are running into the issue with reducing. Looking into DocumenTaskScope.Reduce...

                                                                       

                                                                      docTask.Reduce = new DocumentTask.TaskReduce();

                                                                                      docTask.Reduce.Static = new DocumentTask.TaskReduce.TaskReduceStatic();

                                                                                      List<TaskReduction> TaskReductionList = new List<TaskReduction>();

                                                                                      docTask.Reduce.Static.Reductions = TaskReductionList;

                                                                       

                                                                       

                                                                                      docTask.Reduce.Dynamic = new DocumentTask.TaskReduce.TaskReduceDynamic();  

                                                                                      docTask.Reduce.Dynamic.Type = TaskReductionType.ByField;

                                                                       

                                                                       

                                                                                      docTask.Reduce.DocumentNameTemplate = "%SourceDocumentName%";

                                                                       

                                                                      Hope this helps!