Forum Discussion

bk0615's avatar
bk0615
New Contributor
3 years ago

Check if a task with a specific description is already running

I have a process that causes contention if launched concurrently by users. Is there a way to check if a session with a specific description is already running? I would like to abort the session if another session with the same name is already running. I tried looking through properties and found "GetTaskActivityItem", but the definition and sample are not of much help.

2 Replies

  • JackLacava's avatar
    JackLacava
    Community Manager

    I hate to be that guy, but to me this looks like the wrong way to go about things. If you have an issue with jobs stepping on each other's toes, something went wrong when defining those jobs. This is why Workflow Profiles, for example, enforce entity separation. I'd try to determine why "contention" happens and stop that from happening in the first place. Trying to kill jobs will result in more problems down the line.

  • sudarshan's avatar
    sudarshan
    New Contributor III

    Assuming you are trying to do this in a rule:

    You can query the TaskActivityTable with status = 1000 to indicate it is currently running.

    Dim dt As DataTable = Nothing
    Dim sequence as String = "Task1" 'The name of the DM sequence
    Dim sql As String = "SELECT TaskActivityStatus FROM TaskActivity WHERE Description = '" & sequence & "' AND TaskActivityStatus = 1000"
    'Query the table
    Using dbConnApp As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
       dt = BRAPi.Database.ExecuteSql(dbConnApp,sql,False)
    End Using
    
    'if the following check passes then there is a process currently running
    If dt IsNot Nothing AndAlso dt.Rows.Count < 1
      'Do something
    End If