Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

How to use script block on transition

 Post Reply Post Reply
Author
Adrian Morawiec View Drop Down
New Member
New Member
Avatar

Joined: 29 Dec 2015
Posts: 22
Post Options Post Options   Quote Adrian Morawiec Quote  Post ReplyReply Direct Link To This Post Topic: How to use script block on transition
    Posted: 19 Jan 2017 at 3:27pm
Every transition has script block
I would do some update when transition is use.

how to write correct query?

UPDATE WSTASKINSTANCE
SET STATUS = 'Etap1'
WHERE ID = _Task.Key
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 19 Jan 2017 at 7:05pm
It's highly recommended that you update tasks from Workflow classes. Example:

TI := TTaskInstance.Create(nil);
TI.Key := MyTaskInstanceKey;
WorkflowStudio.TaskManager.LoadTaskInstance(TI);
TI.Status := ‘closed’; //set the status to a final status you want 
WorkflowStudio.TaskManager.SaveTaskInstance(TI);
TI.Free;
Back to Top
Adrian Morawiec View Drop Down
New Member
New Member
Avatar

Joined: 29 Dec 2015
Posts: 22
Post Options Post Options   Quote Adrian Morawiec Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2017 at 8:35am
No, I can't.
I have a few transitions between two blocks. 
When workflow reaches Block 2, I want to know which transition was used.

Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2017 at 11:05am
You can simply put script blocks after each transition and process a custom code for each case. After the script blocks, go to the Block 2.
Back to Top
Adrian Morawiec View Drop Down
New Member
New Member
Avatar

Joined: 29 Dec 2015
Posts: 22
Post Options Post Options   Quote Adrian Morawiec Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2017 at 3:31pm
Can you show me, how to do insert/update in script blocks on every transition?
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2017 at 3:34pm
Actually if you just want to execute an SQL statement, you can use the Database block, which is built for that purpose. Just drop the database block and write the SQL you want to be executed in the database.
Back to Top
Adrian Morawiec View Drop Down
New Member
New Member
Avatar

Joined: 29 Dec 2015
Posts: 22
Post Options Post Options   Quote Adrian Morawiec Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2017 at 3:36pm
Or, how to set adequte internal status on Block 2 depending which transition was used?
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 20 Jan 2017 at 5:35pm
You don't do that in advance. Before the Block 2 is reached, no task is created (I assume Block 2 is a task block, right)? You can't set a task status before it's created. I've been asking you specific and technical questions about database access, but what exactly you want to achieve (at a higher level)?
Back to Top
Adrian Morawiec View Drop Down
New Member
New Member
Avatar

Joined: 29 Dec 2015
Posts: 22
Post Options Post Options   Quote Adrian Morawiec Quote  Post ReplyReply Direct Link To This Post Posted: 23 Jan 2017 at 9:36am
I define new variable.
On every transition i set the variable: my_variable := 'transition1'.
How to read the variable, when workflow reach Block2?
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 23 Jan 2017 at 12:53pm
If you are using a script block, you can access the variable directly from script:

if my_variable = 'transition1' then // ...

If you are using a task block, there are some places you can refer to the variable content using brackets. For example, if you want to include the variable content in the subject or description of the task, you use:

This is "my_variable" content: [my_variable] 
Back to Top
Adrian Morawiec View Drop Down
New Member
New Member
Avatar

Joined: 29 Dec 2015
Posts: 22
Post Options Post Options   Quote Adrian Morawiec Quote  Post ReplyReply Direct Link To This Post Posted: 23 Jan 2017 at 3:15pm
I need to read my variable from application (from Delphi)
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2432
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 23 Jan 2017 at 8:06pm
Once you have the workflow instance key, you can use it to load a TWorkflowInstance object:

WorkIns := TWorkflowInstance.Create(nil, WorkflowStudio);
WorkIns.Key := ATaskIns.WorkInsKey;
WorkflowStudio.WorkflowManager.LoadWorkflowInstance(WorkIns);

VarValue := WorkIns.Diagram.Variables.FindByName(VariableName).Value;
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down