Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Join us at the Cloud Data and Analytics Tour! REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

c# get a list of tasks (I want to start a task)

Hello,

I'm writing a C# application to start a task that is associated with a specific document. I can successfully fetch all the documents from the server and I was thinking that I could quickly use QMSClient.GetTaskForDocument to get the task metadata and then start the job.

I perform a call to QMSClient.GetTasks so that I can get a complete list of tasks, however the call returns nothing. It takes a parameter of QDS ID which I fetch from

QMSClient client = new QMSClient();

string key = client.GetTimeLimitedServiceKey();

ServiceKeyClientMessageInspector.ServiceKey = key;

ServiceInfo[] ServiceList = client.GetServices(ServiceTypes.QlikViewDistributionService);

Guid QvsGuid = ServiceList[0].ID;  // doesn't return the QDS service

QVSSettings QvsSettings = client.GetQVSSettings(QvsGuid, QVSSettingsScope.Distribution | QVSSettingsScope.Documents);               

QDSSettings qdsSettings = client.GetQDSSettings(QvsSettings.Distribution.QDSID, QDSSettingsScope.All);

Guid qdsID = QvsSettings.Distribution.QDSID;

TaskInfo[] t = client.GetTasks(qdsID);

The QDS service is running on the target machine, however I can't seem to get a TaskInfo array. Can anyone suggest to me what modificatoins I need to make in order to make this work?

[EDIT 0] I downloaded power tools onto the machine and am using the QMS client to see what the various functions are returning. The GetServices function doesn't return the distribution service. [/EDIT 0]

[EDIT 1]

Strangely enough, if I run the following code, I can create tasks, however I can never get the list of existing tasks out. It's like I'm not getting the QDS ID correctly.

DocumentTask ta = new DocumentTask();

ta.Document = doc;

ta.QDSID = qdsID;

client.SaveDocumentTask(ta);

[/EDIT 1]

[EDIT 2]

Okay, one more step further. I'm trying to do this via EDX since that's what it looks like EDX is for. I can fetch all the tasks using the FindEDX function, however the task must of course be set up to use EDX. When I create the task, I try to set my task up to use EDX and so I gave it a trigger of ExternalEventTrigger, which doesn't work for me. Whenever I look in the Management console, it says that it's not scheduled (it should say "On EDX"). Anybody know how to create a task that uses EDX?

DocumentTask.TaskReload reload = new DocumentTask.TaskReload();

reload.Mode = TaskReloadMode.Full;

DocumentTask ta = new DocumentTask();

ta.Document = doc;

ta.QDSID = qdsID;

ta.ID = Guid.NewGuid();

ta.Scope = DocumentTaskScope.Reload;

ta.Reload = reload;

DocumentTask.TaskGeneral general = new DocumentTask.TaskGeneral();

general.TaskName = "foobar!";

general.Enabled = true;

ta.General = general;

DocumentTask.TaskTriggering triggering = new DocumentTask.TaskTriggering();

ta.Triggering = triggering;

triggering.Triggers = new Trigger[1];

ExternalEventTrigger eet = new ExternalEventTrigger();

eet.Type = TaskTriggerType.ExternalEventTrigger;

eet.ID = Guid.NewGuid();

eet.Enabled = true;

triggering.Triggers[0] = eet;

[/EDIT 2]

Thanks,

mj

6 Replies
StefanBackstrand
Employee
Employee

mjaskiewicz wrote:

[EDIT 0] I downloaded power tools onto the machine and am using the QMS client to see what the various functions are returning. The GetServices function doesn't return the distribution service. [/EDIT 0]

You don't have a Publisher license. Tasks, or the Distribution Service, will not show up if you don't have a Publisher license.

Not applicable
Author

Stefan,

Thank you for the reply. A bit more though - what about using the EDX stuff like I had later down the post? Is publisher required for this as well?

mj

StefanBackstrand
Employee
Employee

mjaskiewicz wrote:

Stefan,

Thank you for the reply. A bit more though - what about using the EDX stuff like I had later down the post? Is publisher required for this as well?

mj

No, EDX works without Publisher, only you might need to go via the DocumentNodes (or equivalent) in the API to find the tasks (if you want to list them), instead of using the GetTasks methods (that's for Publisher). Non-Publisher (logically) attaches tasks more "directly" on documents, that's why it's like this.

Not applicable
Author

Hello Stefan,

What about the task-creation code in "Edit 2" at the end of my 1st post? I followed your instructions on a different community post, however when I add a task, I don't get the label "On EDX" in QlikView Management Console. Am I setting up the data structures correctly?

Thanks,

mj

yakir_manor
Contributor III
Contributor III

hi mj,

for some reason i just cant get any of the api methods to return all tasks

iv tried the api apiClient.GetTasks and the apiClient.GetTasksForDocument while looping over all docs, nothing worked.

maybe it's because we don't have publisher, finally iv found a work around:

// Initiate backend client

IQMS apiClient = new QMSClient();

// Get QlikView Server

ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey();

var serviceList = apiClient.GetServices(ServiceTypes.QlikViewServer);

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

TaskStatusFilter taskStatusFilter = new TaskStatusFilter();

taskStatusFilter.TaskStatuses = new List<TaskStatusValue>();

taskStatusFilter.TaskStatuses.Add(TaskStatusValue.Aborting);

taskStatusFilter.TaskStatuses.Add(TaskStatusValue.Completed);

taskStatusFilter.TaskStatuses.Add(TaskStatusValue.Failed);

taskStatusFilter.TaskStatuses.Add(TaskStatusValue.Running);

taskStatusFilter.TaskStatuses.Add(TaskStatusValue.Waiting);

taskStatusFilter.TaskStatuses.Add(TaskStatusValue.Warning);

List<TaskStatus> taskStatuses = apiClient.GetTaskStatuses(taskStatusFilter, TaskStatusScope.Extended); // A service call.

foreach (var taskStatus in taskStatuses)

{

    taskInfoList.Add(apiClient.GetTask(taskStatus.TaskID));

}

RohitLsingh
Contributor
Contributor

Hello,

Can you please post the working C# Code.

Thanks,

Regards,
Rohit