AutoScript
start_agent_info
AgentName = "AU_CHATTING_FSM_AGENT"
AgentDescr = "Chatting Coordinator"
AgentLanguage = ""
__timer_interval = 0 {....define (in seconds) the timer interval for the wake up}
__delete_on_termination = 0 {....1=the agent frees itself when terminates its task}
end_agent_info
start_bpm_activity "Chatting"
start_bpm_subactivity "Chatting"
call OpenChatting(__params[1])
end_bpm_subactivity
end_bpm_activity
start_action
mode = __params[1]
if (mode = "START_CHAT") then
rec_id = __params[2]
user = __params[3]
comm = SelectFrom("SELECT CSUBJECT FROM AU_CHAT WHERE (AU_CHAT=",rec_id,")")
__au_process = bpm_createprocess("AU_CHATTING_FSM_AGENT") {....an fsm agent creates itself the process id}
parent_step = GetThrVal("__parent_step")
call UpdateField("AU_PROCESS",__au_process,"COMM",comm,"USER_OWNER",user,"AU_STEP_PARENT",parent_step,"")
call UpdateField("AU_CHAT",rec_id,"AU_PROCESS",__au_process,"COWNER",user,"") {...and maintains it}
call bpm_setprocedureowner(user) {.....set the procedure owner}
call bpm_setprocesscomment(comm)
call bpm_setstepcomment(comm)
call bpm_openatonce()
call bpm_assign_job ( "Chatting" , user , "" , 0 , rec_id )
{..................set infos to the rest of the participants}
start_sql "*" "KOSMOS"
SELECT * FROM AU_CHAT_USER
WHERE (AU_CHAT=:CH)
end_sql
q = QueryByName()
call TSetParam(q,"CH",rec_id)
call TExecute(q)
count = TRecordCount(q)
call TFirst(q)
for i = 1 to count
user_i = TGetFld(q,"AU_USER")
user_i = SelectFrom("SELECT UNAME FROM AU_USER WHERE (AU_USER=",user_i,")")
dummy = bpm_assign_info ( "Chatting", user_i, "", rec_id )
call TNext(q)
next
call FreeEmbSQL(q)
endif
if (mode = "MODIFY_CHAT") then
rec_id = __params[2]
comm = SelectFrom("SELECT CSUBJECT FROM AU_CHAT WHERE (AU_CHAT=",rec_id,")")
__au_process = SelectFrom("SELECT AU_PROCESS FROM AU_CHAT WHERE (AU_CHAT=",rec_id,")")
{..................set infos to the rest of the participants (only the new ones)}
start_sql "*" "KOSMOS"
SELECT * FROM AU_CHAT_USER
WHERE (AU_CHAT=:CH)
end_sql
q = QueryByName()
call TSetParam(q,"CH",rec_id)
call TExecute(q)
count = TRecordCount(q)
call TFirst(q)
for i = 1 to count
user_i = TGetFld(q,"AU_USER")
user_i = SelectFrom("SELECT UNAME FROM AU_USER WHERE (AU_USER=",user_i,")")
au_step = SelectFrom("SELECT AU_STEP FROM AU_STEP WHERE (PARAMS = '",rec_id,"') AND (UNAME='",user_i,"')")
au_step = val(au_step)
if (au_step = 0) then
dummy = bpm_assign_info ( "Chatting", user_i, "", rec_id )
endif
call TNext(q)
next
call FreeEmbSQL(q)
endif
end_action
end_action