> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/best-practices-screensteps/querying-active-tasks.md).

# Querying active tasks

{% code overflow="wrap" lineNumbers="true" %}

```javascript
String processName = '{process_Name}'; //name of related process

String processVersionName = '{process_version_name}'; //name of related process version

String objectId = '{object_id}'; //id of the record flow instance is running on

String cursorAssignedTo = '{assigned_to}';  // assignee value of an active cursor.
// Value depends on step assign type: 
// if assign type is 'User' cursorAssignedTo will store single user id or string with coma separated user ids. 
// If assign type is  'Group', 'ChatterGroup', 'Queue', 'Role', 'Profile' cursorAssignedTo will store corresponding record Id. 
// If assign type is 'Call Apex' cursorAssignedTo will store result of apex method execution (single user id, string with coma separated user IDs, Role, Profile, Group ID etc). 
// If step assign type is 'Field' cursorAssignedTo will store string value of the corresponding field or comma separated values of multiple fields if one added multiple fields as step assignee. 
// If assign type is 'System' cursorAssignedTo will store string 'System'. 
// If assign type is 'Variable' it will store variable value.

String stepAssignedTo = '{assign_to}'; //assignee value of a step related to an active cursor. 
// Value depends on step assign type: if step assign type  is 'User' stepAssignedTo will store single user id or string with coma separated user ids.  
// If assign type is 'Group' / 'ChatterGroup' / 'Queue' / 'Role' / 'Profile' stepAssignedTo will store corresponding record Id.  
// If assign type is field, stepAssignedTo will store field api name or comma separated fields api names.  
// If assignee type is 'Apex' it will store apex class api name.  
// If assign type is 'System' stepAssignedTo will store string 'System'.  
// If assignee type is 'Variable' stepAssignedTo will store variable name. 

String stepName = '{step_name}'; //name of related process step

String swimlaneName = '{swimlane_name}'; //name of swimlane related process step belongs to

List<WR_BPM__Flow_Instance_Cursor__c> = [SELECT id from WR_BPM__Flow_Instance_Cursor__c where
WR_BPM__Flow_Instance__r.WR_BPM__Flow__r.WR_BPM__Process__r.Name = :processName AND
WR_BPM__Flow_Instance__r.WR_BPM__Flow__r.Name = :processVersionName AND
WR_BPM__Flow_Instance__r.WR_BPM__Object_Id__c = :objectId AND
WR_BPM__Step_Assigned_To__c = :cursorAssignedTo AND 
WR_BPM__Step_Assign_To__c = :stepAssignedTo AND
WR_BPM__Step__r.Name = :stepName AND
WR_BPM__Swimlane__c = :swimlaneName AND
WR_BPM__Status__c = 'In Progress' AND WR_BPM__Flow_Instance__r.WR_BPM__Is_Active__c = true];
```

{% endcode %}
