Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stumped: Error with WAPI.taskdone (Auto complete Workflow Step)

Status
Not open for further replies.

supernutters

Programmer
Mar 11, 2014
4
SG
Hi All,

I am currently trying to auto-complete some parallel workflow steps using the WAPI.taskdone function via event scripts. When i run the event script through the livelink builder debugging mode, my event script runs fine. However, when i run my script normal, the WAPI.taskdone function throws an SQL error. I have turned on the database logs and found that this error is due to WAPI.taskdone trying to insert an entry into the wlock table so as to create a softlock. However, when the event script is run, an entry of the workflow is automatically put into the wlock table thus causing there to be a duplicate entry which causes the SQL error. The weird thing is also when run in debugging mode, no soft lock is done thus no error is thrown when run in debugging mode. Would any of the kind folks out there advise on an alternative way in which i can complete steps via event scripts. Do help out here as i am so stumppeedddddd.

Thanks!
Regards
Mark
 
I am not sure if you are running into a developer chicken and egg problem.The WF steps are run in a transaction so that all steps in that your event scripts,ot's all return true.It is all or nothing.

so you have to know whether or not your wapi session has a valid transaction something as in
Object session = prgCtx.WSession()
Dynamic status

Then
if ( session.StartTrans() )
status = WAPI.TaskDone( work, true)
end

I am also not sure if you are supposed to start your own transaction as well but I do it whenever I need
to do capi stuff

if you are not wrapping it or checking whether you are part of a valid transaction unforeseen errors can happen.
BTW are you using the workhandle that the eventscript passes in to you or do you create your own handle.
Also the wlock table has a single purpose.A WF step can be done in many ways,human,programmatic etc.So if we assume the simplest case
as in a step has been assigned to a group and it bcomes ready.You are at the gui trying to finish the task.A wlock entry is needed to prevent others from doing it.So after you are done and if the taskdone works then the lock is automatically revoked by the code.

I would also try to do it without doing WAPI kind of work because it is too low level
Perhaps $WFMain.WAPIPkg.FinishTask with the right params would that also do what you are trying to get done....
I usually look in builder at APIWORK and try to find a parallel in what I am trying to do in code which many times are eventscripts...



Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
Hi Appnair,

Thanks so much for the response. i am unable to currently using workhandle that eventscript passes me as when i use it, WAPI.TaskDone says the handle is in use. i had to use WAPI.Freework to free up the existing work handle and then allocate a new one to it.

I also tried to use $WFMain.WAPIPkg.FinishTask however it has the same error as in the method it also uses WAPI.TaskDone. Currently, i am able to workaround the issue by doing a delete from the wlock table before i call the WAPI.TaskDone method. Would like to seek your kind advise if this workaround would be ok? Would you have any alternative methods in which i am able to perform the WAPI.Taskdone?

Thanks alot!
Best Regards
Mark
 
H'mm that may be your problem.But here is what I will do as I know nothing about really what you are trying to do.If my assumption is You have a Group step and you want to make sure that some people have done work and you are trying to get the other peoples work done by event scripting.Here is what I will do.

1)Create the condition in a instance
2)Run DEBUG=2 and wantlogs=true in opentext.ini
3)Check if workid is in the wlock table
4)Bring up wf instance gui and do everything as the event script would do.
5)Take special precaution noting down what you push especially if it was 'Send On' or an actual disposition condition
6)Do it and see if the TASK is done
7)Looks in logs directory for any traces et al
8)See if work completes and nl locks/traces et al

If that proves good then you may just have to make sure you follow that in event scripting.

WAPI.FREEWORK etc are dangerous calls in oscript .If you need me to look at your event script send it to me.There is a guy in your org who has my email and I have hlped before say hi to him.


Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
Hi appnair,

i created 3 steps in the workflow map. when step 1 is executed, it runs a event script. Once an event script is executed, it seems that when the workflow is executing the ecent script, it puts in a lock thus the WAPI.TaskDone is unable to execute which results in a SQL error. is there any wapi calls which would allow me to unlock the wlock? i have attached my script below for your kind reference. Thanks a MIL!

Function Dynamic endTask( Object prgCtx, WAPIWORK work, Integer workID, Integer subWorkID, Integer taskID, Integer returnSubWorkID, Integer returnTaskID, Dynamic extraData = Undefined )
Dynamic status


String cnctName = $Kernel.SystemPreferences.GetPrefGeneral( 'DftConnection' )

Assoc prgAssoc = $LLIApi.PrgSession.CreateNewNamed( cnctName, { "Admin", undefined } )

prgCtx = prgAssoc.pSession

Object session = prgCtx.WSession()

Integer flags = WAPI.STARTTASK_FLAG_REEXECUTE | WAPI.STARTTASK_FLAG_NOAUDIT | WAPI.STARTTASK_FLAG_FORTASKDONE

work= session.AllocWork()
status = WAPI.StartTask( work,WorkID,SubWorkID, 1,flags )
echo (status)
status = WAPI.TaskDone(work,ture) // complete all links which equals true
echo (status)

end
 
why are you not using the prgctx passed in? what you are essentially doing is basically starting another connection to the database as the 'Admin' user and after you are done you are not releasing the prgCtx. There is basically no transaction safety in the code.Are you using Admin's context because the step user who is executing does not have perms to execute the step.These should all be done at design time by assigning the right permissions of people to the step.The creation of the prgctx is transaction counted so by increasing it out of context puts the livelink system in imbalance as well.

I will try to help but can you post your workflow map some where so I can download it and help and perhaps some description on what you are trying to achieve?

It is not clear from your posting what your map looks liek whether they are serial or parallel


Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
Hi Appnair,

Wow. thanks so much for your help. Please kindly find the Map at
So i have actually done a workaround. It does the following steps
1) Free the work instance as the current work handle is currently in used.
2) Allocate a new work handle
3) Start the current Map Task
4) delete the workflow lock by doing a database delete from the wlock table
5) Complete the workflow step
6) insert back the workflow lock by doing a database insert into the wlock table.

Could i seek your advice if the above steps is ok? it seems like i am kind of hacking the wlock table to execute my WAPI.endTask and if done incorrectly might crash the system.

Thanks in advance!


Function Dynamic CancelVersion3( Object prgCtx, WAPIWORK work, Integer workID, Integer subWorkID, Integer taskID, Integer returnSubWorkID, Integer returnTaskID, Dynamic extraData = Undefined )
Integer linkCond = WAPI.TRUE
Dynamic status,taskrec
Integer flags = WAPI.STARTTASK_FLAG_REEXECUTE | WAPI.STARTTASK_FLAG_NOAUDIT | WAPI.STARTTASK_FLAG_FORTASKDONE

Record task,taskRecord

String cnctName = $Kernel.SystemPreferences.GetPrefGeneral( 'DftConnection' )

Assoc prgAssoc = $LLIApi.PrgSession.CreateNewNamed( cnctName, { "Admin", undefined } )

prgCtx = prgAssoc.pSession

WAPI.FreeWork(work)
work = prgCtx.WSession().AllocWork()

status= WAPI.StartTask( work, workID,subWorkID, 1, flags )
delete(prgCtx,workID)

status = WAPI.TaskDone( work, linkCond )
echo(status)

insert(prgCtx,workID)


end


function assoc delete(Object prgCtx, workid)


String databasequery = Str.Format("delete wlock where wlock_workid = %1",workid)
CAPI.Exec(prgCtx.fDBConnect.fConnection, databasequery)
echo("SQL Checkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk delete")




end
 
I looked at you map and put your script in a CS10 Upd 11 version.I am not able to further guide you because I am not sure what you are planning to do.
For e.g when I bring up your map it is some thing like this I have to write because I can't show the picture
Start Step-> USer1
Start Step->User2->MileStone->Initiator
I put your Event Script on the User2 step when it is at the vent step is done
I first tried it with the Admin context and put echo after your code...
Mind you I am doing this all not with builder that is probably why yours i going into lock....
03/25/2014 16:50:22 ******************************************* STARTTASK CALLED
03/25/2014 16:50:22 0
03/25/2014 16:50:22 ******************************************* TASKDONE CALLED
03/25/2014 16:50:22 Instance already locked.

There is no lock in my wlock and the User1 step is in Green and Initiator is in Green
If I remove the admin PrgCtx and run it with the passed in the error message changes to

3/25/2014 16:57:14 _REQUEST = 'llweb'
03/25/2014 16:57:14 ******************************************* STARTTASK CALLED
03/25/2014 16:57:14 0
03/25/2014 16:57:14 ******************************************* TASKDONE CALLED
03/25/2014 16:57:14 Instance already locked.
03/25/2014 16:57:14 Tue Mar 25 16:57:14 2014 - 102118 Func='work.taskdone'

So there is no real difference.I know that you are trying to do some problem for real and threw a map for that and running into difficulties
My understanding is TaskDone sets that current task to DONE as a user did it and then moved to the logial path .In both cases in your map and code it never went into wlock so I never had to release it from wlock. Was the user steps a group step?

If you are in correctly thinking that TaskDone is a convenience feature for making all the steps in a workflow go to completion that assumption is wrong

You have to load the running map and run it to completion using loops etc...






Well, if I called the wrong number, why did you answer the phone?
James Thurber, New Yorker cartoon caption, June 5, 1937
Certified OT Developer,Livelink ECM Champion 2008,Livelink ECM Champion 2010
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top