Enabling and Disabling Tasks Remotely using the TaskCentre API

Enabling and Disabling Tasks Remotely using the API

We have had some interest to be able to enable or disable tasks remotely outside of TaskCentre to enable non TaskCentre administrators to have control over enabling and disabling tasks.

This can be achieved by using vb script triggered from a webpage using the example code below.

Note: The TaskCentre client MUST be installed at the script origin as it calls the Iwcltcp.TCAPI method.
Host = TaskCentre Server Name/IP
User = Username for user who has access 'Script Object Access' set in the users screen
Password = This users password

TaskId = xxx  ' Set the task id you wish to enable/disable here.
Set myAPI = CreateObject("Iwcltcp.TCAPI")
Set mySession=myAPI.Logon (1,"host","user","password")
Set myTaskItem=mySession.OpenTaskItem(TaskId)
myTaskItem.Disabled=true
'myTaskItem.Disabled=false

The Contents property on a Folder object provides access to the task objects within it.

This example enables all the tasks in the top level “Tasks” folder:

set myapi=CreateObject("iwcltcp.tcapi")
set mysession=myapi.Logon (1,"host","user","password")
set myfolders=mysession.Folders
set myContents=myfolders("Tasks").Contents

for i=0 to myContents.Count -1
myContents(i).Disabled=false
msgbox("I have just enabled " & myContents(i).Name)
next

You can get the folders too. As well as Contents property which is a collection of tasks, the folder object has a ChildFolders property which contains all of its sub folders.
Using the example above, changing the line where myContents is set will enable all the tasks in “Tasks\FolderName”:

set myContents=myfolders("Tasks").ChildFolders("FolderName").Contents

The ChildFolders object is a collection like the Contents object, so you can loop through it and access individual folders by index too:

for i=0 to myfolders("Tasks").ChildFolders.Count -1
msgbox("sub folders " & myfolders("Tasks").ChildFolders(i).Name)
next

This example will disable every task in the store:

for i=0 to thisFolder.ChildFolders.Count -1
DisableAllTasks(thisFolder.ChildFolders(i))
next
set myContents=thisFolder.Contents
for i=0 to myContents.Count -1
myContents(i).Disabled=true
msgbox("I have just disabled " & myContents(i).Name & " in folder " & thisFolder.Name)
next
end function

set myapi=CreateObject("iwcltcp.tcapi")
set mysession=myapi.Logon (1,"host","user","password")
set myfolders=mysession.Folders

See Also Starting a Task From within another Task