Operation Details
Description: Returns a count of all of the tasks reserved by the specified users for all of the organization unit s that the user is subscribed to.
Sterotype: nsmulti
SQL
SELECT
  ta.relatedID,
  count(*)
INTO
  :workQueueID,
  :numberOfRecords 
FROM
  TaskAssignment ta 
WHERE ta.assigneeType = :assigneeType 
  AND ta.relatedID IN 
  ( 
  SELECT
    wq.workQueueID 
  FROM
    WorkQueue wq 
  WHERE wq.workQueueID IN 
    ( 
    SELECT
      workQueueID 
    FROM
      WorkQueueSubscription wqs 
    WHERE wqs.subscriberType = :subscriberType 
      AND wqs.subscriberID IN 
      ( 
      SELECT
        DISTINCT ou.organisationUnitID 
      FROM
        Users u ,
        PositionHolderLink ph ,
        Position p ,
        OrgUnitPositionLink oup ,
        OrganisationUnit ou 
      WHERE u.userName = :userName 
        AND u.userName = ph.userName 
        AND ph.positionID = p.positionID 
        AND p.positionID = oup.positionID 
        AND oup.organisationUnitID = ou.organisationUnitID 
        AND ph.recordStatus = :recordStatus 
        AND :currentDate >= ph.fromDate 
        AND 
        (
          :currentDate <= ph.toDate 
          OR ph.toDate IS NULL 
        ) 
      ) 
    ) 
  ) 
  AND ta.taskID IN 
  ( 
  SELECT
    taskID 
  FROM
    Task t 
  WHERE t.reservedBy = :userName 
    AND t.taskID = ta.taskID 
  ) 
GROUP
  BY ta.relatedID