Do not let any software impress you!

Only let it convince your intellect.
Slider img 1
Do not look for a business paradise!

It is a waste of time.
Slider img 2
Only yourself can push you uphill.

There is no easy road to prizes.
Slider img 3
Productivity is the name of the game.

And you have to conquer it.
Slider img 4
As long as you understand it,

you will start to build your know-how.
Slider img 5
We can help with that.

We have the tools and the method.
Slider img 6
Procedure : AU_TASK_COORDINATOR

AutoScript

start_agent_info
         AgentName = "AU_TASK_COORDINATOR"
         AgentDescr = "Assignment and Follow-up Coordinator"
         AgentLanguage = ""
         __timer_interval = 0
         __is_registered = 1
         __delete_on_termination = 0
end_agent_info

start_bpm_activity "Task Definition"
start_bpm_subactivity "Task"

    rec = __params[1]
    expr = strcat(rec,"=AU_TASK")
    call OpenFormTop("ptEdit","AU_TASK_E03.FM","WORK.AU_TASK",1,expr)
        
end_bpm_subactivity
end_bpm_activity

start_bpm_activity "Task Execution"
start_bpm_subactivity "Task"

    rec = __params[1]
    expr = strcat(rec,"=AU_STASK")
    call OnOpenForm_DisableAllFields()
    call OnOpenForm_EnableField("COMM")
    call OpenFormTop("ptEdit","AU_STASK_E02.FM","WORK.AU_STASK",1,expr)
                
end_bpm_subactivity
end_bpm_activity

start_bpm_activity "Task Checking"
start_bpm_subactivity "Task"

   rec   = __params[1]
   expr = strcat(rec,"=AU_STASK")
   call OnOpenForm_DisableField("DESCR")
   call OpenFormTop("ptEdit","AU_STASK_E04.FM","WORK.AU_STASK",1,expr)

end_bpm_subactivity
end_bpm_activity

start_action

     task_id = __params[1]
     comm      = LookUpId("AU_TASK",task_id,"DESCR")     
     bus_id     = LookUpId("AU_TASK",task_id,"AU_BUSINESS")     

     call bpm_setprocedureowner(__activation_user)                     {.....set the procedure owner}
     call bpm_setprocedurecomment(comm)                          {.....set the procedures comment}
     call bpm_setprocessbusiness(bus_id)
        
     call bpm_openatonce()
     callwait bpm_assign_job ( "Task Definition" , __activation_user , "" , 0 , task_id )

     c1      = LookUpId("AU_TASK",task_id,"DESCR")
     bus_id = LookUpId("AU_TASK",task_id,"AU_BUSINESS")
     bus      = LookUpId("AU_BUSINESS",bus_id,"TITLE")                    
     msg      = LookUpId("AU_TASK",task_id,"COMM")

     eenddate = LookUpId("AU_TASK",task_id,"EENDDATE")
                        
     comm     = c1
     call bpm_setprocedurecomment(comm)                          {.....set the procedures comment}

     {.............................get the number of users to whoom job has been assigned}
     start_sql "*" "KOSMOS"
       SELECT AU_TASK.*, AU_TASK_USER.*, AU_TASK_USER.AU_USER AS USERID
       FROM AU_TASK, AU_TASK_USER
       WHERE (AU_TASK.AU_TASK = AU_TASK_USER.AU_TASK) AND (AU_TASK.AU_TASK = :T)
     end_sql
     q = QueryByName()
     call TSetParam(q,"T",task_id)
     call TExecute(q)
     user_count = TRecordCount(q)

     call TFirst(q)
     for i = 1 to user_count

         user_id = TGetFld(q,"USERID")                
         user[i] = LookUpId("AU_USER",user_id,"UNAME")

         flag = strcomp(user[i],"")
         if (flag = 1) then
         user_count = i - 1
         i = 100
         endif
         if (flag = 0) then

         {.........................insert the subtask.........................}
         start_sql "*" "KOSMOS"
         INSERT INTO AU_STASK
         end_sql
         st = QueryByName()
         call TSetFld(st,"DESCR","String",c1)
         call TSetFld(st,"EENDDATE","DateTime",eenddate)
         call TSetFld(st,"AU_TASK","String",task_id)
         call TSetFld(st,"COMM","String",msg)
         call TSetFld(st,"TOUSER","String",user_id)
         call TSetFld(st,"AU_BUSINESS","String",bus_id)
         call TExecute(st)
         call FreeEmbSQL(st)
        
         stask_id[i] = SelectFrom("SELECT MAX(AU_STASK) FROM AU_STASK")

         {......................set also the same document relations.................}
         start_sql "*" "KOSMOS"
         SELECT * FROM AU_DOC_REL
         WHERE (REL_TABLE_NAME = "AU_TASK") AND
                 (REL_REC_ID = :R)
         end_sql
         q1 = QueryByName()
         call TSetParam(q1,"R",task_id)
         call TExecute(q1)
         rcount = TRecordCount(q1)
         call TFirst(q1)
         for j = 1 to rcount
                au_doc = TGetFld(q1,"AU_DOC")
                reldate = TGetFld(q1,"RELDATE")

                start_sql "*" "KOSMOS"        
                 INSERT INTO AU_DOC_REL
                end_sql
                at = QueryByName()
                call TSetFld(at,"REL_TABLE_NAME","String","AU_STASK")
                call TSetFld(at,"REL_REC_ID","String",stask_id[i])
                call TSetFld(at,"AU_DOC","String",au_doc)
                call TSetFld(at,"RELDATE","DateTime",reldate)
                call TExecute(at)
                call FreeEmbSQL(at)
                
                call TNext(q1)
         next
         call FreeEmbSQL(q1)
        
         endif
        
         call TNext(q)
     next
     
     call FreeEmbSQL(q)
     
     {.............................parallel execution of the user assigned jobs}
     split_for i = 1 to user_count
     
         for j = 1 to 1000

         finished = LookUpId("AU_STASK",stask_id[i],"FINISHED")
         user_id = LookUpId("AU_STASK",stask_id[i],"TOUSER")
         user[i] = LookUpId("AU_USER",user_id,"UNAME")

         comm = c1
         comm2 = strcat(j," - ",comm)
         call bpm_setstepcomment(comm2)
                                                        
         if (finished = 1) then

                 j = 1000

         endif

         if (finished = 0) then

                 msg = SelectFrom("SELECT COMM FROM AU_STASK WHERE (AU_STASK = ",stask_id[i],")")
                 msg = strcatln(msg)

                 msg = strcatln(msg,"------------------------------------------------------")
                 start_sql "*" "KOSMOS"
                 UPDATE AU_STASK
                 WHERE (AU_STASK = :S)
                 end_sql
                 st = QueryByName()
                 call TSetParam(st,"S",stask_id[i])
                 call TSetFld(st,"COMM","String",msg)
                 call TExecute(st)
                 call FreeEmbSQL(st)
                
                 call bpm_setstepfinaldate(eenddate)
                 callwait bpm_assign_job ( "Task Execution" , user[i] , "" , 0 , stask_id[i] )

                 {.....the task issuer examines if the task is completed, or reassinges it again (to the same or different person}
                                
                 msg = SelectFrom("SELECT COMM FROM AU_STASK WHERE (AU_STASK = ",stask_id[i],")")
                 msg = strcatln(msg)

                 msg = strcatln(msg,"------------------------------------------------------")
                 start_sql "*" "KOSMOS"
                 UPDATE AU_STASK
                 WHERE (AU_STASK = :S)
                 end_sql
                 st = QueryByName()
                 call TSetParam(st,"S",stask_id[i])
                 call TSetFld(st,"COMM","String",msg)
                 call TExecute(st)
                 call FreeEmbSQL(st)

                 comm1 = strcat(j," - ",user[i]," - ",comm)
                 call bpm_setstepcomment(comm1)
                 callwait bpm_assign_job ( "Task Checking" , __activation_user , "" , 0 , stask_id[i] )

         endif

         next
        
     next_branch
        
end_action