You are viewing limited content. For full access, please sign in.

Question

Question

Please help to resolve errors in following code

asked on February 26, 2014

wfoptions = new SearchFilterOptions()            

wfoptions.Statuses = SearchFilterOptions.WorkflowStatus[]{SearchFilterOptions.WorkflowStatus.Running}

 

Errors are:

Error    1    'WorkflowStatus' is a type in 'Laserfiche.Workflow.Objects.SearchFilterOptions' and cannot be used as an expression.    \TerminateWorkflowsonthebasisofentryID\Script 1.vb    34        Script_terminate

Error    2    Identifier expected.    \TerminateWorkflowsonthebasisofentryID\Script 1.vb    34        Script_terminate

Error    3    'Laserfiche.Workflow.Objects.Options' is a namespace and cannot be used as an expression.    \TerminateWorkflowsonthebasisofentryID\Script 1.vb    40        Script_terminate

 

 

 

 

0 0

Answer

SELECTED ANSWER
replied on March 19, 2014 Show version history

You need to create the connection because the script has no idea that it is running on the same machine as the Workflow server. No matter what you have to tell it where to look, even if the server is local.

 

EDIT: I posted the below solution for avoiding hardcoding but forgot that it won't work for Workflow scripts. If you have a standalone application, it will work fine. For this Workflow script, you can just use "localhost" as the server since the script will always run on the Workflow server.

 

As far as not hardcoding the value of the server name, I would recommend storing the name in your application settings. Do note that you should not store sensitive information like passwords there, as they are stored as plaintext. The advantage of this is that later, you can edit the app.config file and change the server that your application will connect to without having to rebuild the application.

1 0

Replies

replied on February 26, 2014 Show version history

I think I see your issues:

wfoptions.Statuses = SearchFilterOptions.WorkflowStatus[] {SearchFilterOptions.WorkflowStatus.Running}

should be

wfoptions.Statuses = SearchFilterOptions.WorkflowStatus() {SearchFilterOptions.WorkflowStatus.Running}

In C#, [] denotes an array. The equivalent in VisualBasic is (). This is causing both of your line 34 errors.

 

The other issue looks like you forgot to update a variable name when translating from C#:

for each wfresult in wfcon.Database.Tracking.SearchWorkflowInstances(options)

should be updated to

for each wfresult in wfcon.Database.Tracking.SearchWorkflowInstances(wfoptions)

Those two fixes should fix the errors you've posted.

 

Also, for future reference, when you're putting together a post or a reply (or editing), the top bar has a code button that you can use to input code with formatting and syntax highlighting (make sure to set the language in the pop-up to get the proper highlighting!):

2 0
replied on February 26, 2014

Can you post the entire script? It looks like you're trying to use the script from this post, but are either missing references or not converting it to VB properly.

 

Please also see the discussion on performance implications on this other thread.

0 0
replied on February 26, 2014

Miruna, below is my script. Is there any other way using when any user can terminate workflow when required.?

 

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Imports LFSO83Lib
Imports Laserfiche.Workflow
Imports Laserfiche.Workflow.Objects
Imports Laserfiche.Workflow.Objects.Instances

Namespace WorkflowActivity.Scripting.TerminateWorkflowsonthebasisofentryID
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits SDKScriptClass83
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()
            Dim wfcon as WorkflowConnection
            Dim wftostart as PublishedWorkflow
            Dim wfoptions as SearchFilterOptions
            Dim wfresult as SearchResult
            Dim wfinstance as WorkflowInstance
            Dim wfentry as StartingEntry
            Dim wfinitiator as Initiator


            wfcon = WorkflowConnection.CreateConnection("Workflow Server Name", "Sample")
            wftostart = wfcon.Database.GetPublishedWorkflow("Insert Workflow Name Here")
            wfoptions = new SearchFilterOptions()
            wfoptions.Statuses = SearchFilterOptions.WorkflowStatus[]{SearchFilterOptions.WorkflowStatus.Running}

            wfoptions.MinEntryId = 1  'Fill in your entry id here
            wfoptions.MaxEntryId = 1


            for each wfresult in wfcon.Database.Tracking.SearchWorkflowInstances(options)
                wfinstance = wfresult.WorkflowInstance
                wfentry = wfinstance.StartingEntry
                wfinitiator = wfinstance.Initiator
                wfinstance.Terminate("Testing Termination using script")
                'workflowToStart.StartWorkflow("Insert another workflow to start here", entry, initiator, null, null)
            next
        End Sub
    End Class
End Namespace

 

0 0
replied on March 19, 2014

Thanks Matthew,

Now my script is not throwing any kind of error. Also, I'm able to establish connection with workflow server.

But now the problem is that I'm not getting anything in wfoptions.statuses.

Control is not going into for each loop.

 

0 0
replied on March 19, 2014

It's resolved now.

I'm now using

wfoptions.Statuses = SearchFilterOptions.WorkflowStatus[]{SearchFilterOptions.WorkflowStatus.Active}

instead of

wfoptions.Statuses = SearchFilterOptions.WorkflowStatus[]{SearchFilterOptions.WorkflowStatus.Running}

 

Now just wondering, since we are running our script on workflow server itself then why there is need to create new connection using

wfcon = WorkflowConnection.CreateConnection("Workflow Server Name", "Sample")

?

 

Is this the correct way? Or there is some other way to get the server name instead of hardcoding its value?

0 0
SELECTED ANSWER
replied on March 19, 2014 Show version history

You need to create the connection because the script has no idea that it is running on the same machine as the Workflow server. No matter what you have to tell it where to look, even if the server is local.

 

EDIT: I posted the below solution for avoiding hardcoding but forgot that it won't work for Workflow scripts. If you have a standalone application, it will work fine. For this Workflow script, you can just use "localhost" as the server since the script will always run on the Workflow server.

 

As far as not hardcoding the value of the server name, I would recommend storing the name in your application settings. Do note that you should not store sensitive information like passwords there, as they are stored as plaintext. The advantage of this is that later, you can edit the app.config file and change the server that your application will connect to without having to rebuild the application.

1 0
replied on March 24, 2014 Show version history

One more query on this one.

 

for each wfresult in wfcon.Database.Tracking.SearchWorkflowInstances(options)

 

This for each is running only for 50 wfresult objects and not going beyond fifty iterations.

 

Anything I can do to get all search results?

 

I can see that the workflow for which I'm doing this search has 582 active iterations.

This time I'm searching workflow instances not on the basis of Entry ID but on the basis of WorkflowName.

 

wfoptions.WorkflowName = "ABC"

 

Please help ASAP.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.