Create and Take Task¶
Create and Take Task will allow the Mate to create a Task and at the same time take that Task, and return the Task object.
Be aware that Task is also locked
Notice that when the Task is taken, it is locked for other users and other Mates.
Details¶
The main use-case that we have seen for Create and Take Task is when migrating legacy robots to Anymate. Sometimes, if a Robot is working it will make sense to migrate it to Anymate without changing too much. With Create and Take Task, it is possible for a Mate to create tasks and immediatly take them to be solved. This way, it is easy to get started and possible to use many of Anymates features without completely rewriting and refactoring the Robot.
To learn more about what is possible when creating a Task, please see Create Task. Likewise, to learn more about the Task object when getting a task, please see Take Next.
Example¶
The endpoint is found at https://{ClientId}.anymate.app/api/CreateAndTakeTask/{ProcessKey} The http-request must be submitted as a POST with JSON encoded data.
curl --request POST \
--url https://{ClientId}.anymate.app/api/CreateAndTakeTask/{ProcessKey} \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjgyQ0JGNDY3NEMyMUExRjBCMjhFNzlBNTk5MzAwQjdBIiwid.....' \
--header 'Content-Type: application/json' \
--data '{
"comment": "Type in a new comment here",
"activationDate" : "2021-01-01",
"coreSystemKey": "key value as string",
"dropdownField": "Dropdown example",
"textField": "Text example",
"numberField": 999.99
}'
ClientId and ProcessKey
If you don't remember what your client Id is, you can find it here. You can see where to find the ProcessKey and more information on Developer help here
Once submitted, the exact Task that was just created will be returned.
{
"taskId": 1,
"reason": "Reason Example",
"runId": 1,
"processKey": "myProcessKey",
"coreSystemKey": "key value as string",
"dropdownField": "Dropdown example",
"textField": "Text example",
"numberField": 999.99
}
Using the Anymate .NET SDK, the CreateAndTakeTask method in IAnymateService will let you create a Task and return the Task immediatly. It takes either any type of object you create yourself or a json string. It will as default return a json string but it is possible, as shown in the example below, to give a class as a Generic Type Argument and have it deserialized automatically.
using Anymate;
//code omitted
//Create AnymateService object
var anymateService = new AnymateService(client_id, client_secret, username, password);
// Here we use an anonymous type to make the new Task object.
// Make sure that the attributes have the correct names.
var newTask = new
{
comment = "Type in a new comment here",
activationDate = new DateTime(2021, 01, 01),
coreSystemKey = "key value as string",
dropdownField = "Dropdown example",
textField = "Text example",
numberField = 999.99
};
// Create the task with the newTask object we just created and the ProcessKey to ensure it is created on the correct process.
// Here we use a 'MyTaskModel' class we made to deserialize the Task as we receive it.
var createdTask = anymateService.CreateAndTakeTask<MyTaskModel>(newTask, processKey);
long taskId = createdTask.TaskId;
// code omitted
Using the Anymate Python SDK, simply invoke the create_and_take_task
function in anymate.client.
import anymate
# code omitted
# Initialize the client
client = anymate.client(client_id, api_secret, username, password)
# We create the new task as a dict
newTask = {
'comment': "Type in a new comment here",
'coreSystemKey': "key value as string",
'dropdownField': "Dropdown example",
'textField': "Text example",
'numberField': 999.99
}
# Create the task in Anymate and get the created task as a dict
created_task = client.create_and_take_task("targetProcessKey", newTask)
# Read the TaskId of the new task
taskId = created_task['taskId']
create_and_take_task
takes a dictionary or object as input. It returns a dict as output.
Using the Anymate UiPath SDK, simply invoke the Create and Take Task
activity.
Create and Take Task
takes either a Dictionary Payload (with string key and string value) and optionally a Comment or a JSON formatted string as input, if e.g. the Developer
prefers to serialize a object directly. Don't worry - Anymate ensures that anything formatted as a string, will be formatted to the correct type before you get the Task back.
Create and Take Task
will return a Task object in the format of a JObject, where each key/value can be invoked similar to how it would be done with a Dictionary. It is also possible to get the Task out as a JSON formatted string.