Uploading content with no prompts

Build 1501 on 14/Nov/2017  This topic last edited on: 26/Oct/2016, at 21:02

In client software, you can upload files to server and pass them to a workflow without any interaction, that is, without displaying the workflow dialog.

This allows, for example, to drag&drop files on a Shell view and to make the new created GN4 objects being automatically added to the list.

A new method, called ExecuteWorkflowNoDialog, has been added to the MainAddIn.App script object.

In the following example, we override the OnDropExternal() method in CustomTedWindowAddIn (CustomTed.vb file): this is the method that receives the list of client paths when the user drags&drops files in Ted4.

We call the standard ImportActivityData workflow using the new ExecuteWorkflowNoDialog method to import the dropped files into the database without interaction.

Note that both the uploading process and the call to the workflow are asynchronous: this means that the user can continue to work after having dropped the files.

Public Overrides Function OnDropExternal(ByVal droppedFiles As String()) As Boolean

  If Not droppedFiles Is Nothing AndAlso droppedFiles.Count > 0 Then

    'upload the files to the server and call the workflow

 

    'set the folder where the GN4 objects will be created

    Dim parameters As Specialized.NameValueCollection = New Specialized.NameValueCollection()

    parameters.Add("folderPath", EditorialLogin.GetLogin.GetContextObj()?.HomeFolderPath)

    'execute the workflow

    App.ExecuteWorkflowNoDialog("ImportActivityData", Nothing, parameters, droppedFiles, Nothing)

    Return true

  End If

  Return False

End Function

Note also that the ImportActivityData requires the "folderPath" parameter (in the example, it is set to the user's home folder).

The ExecuteWorkflowNoDialog method accepts the following parameters:

the name of the workflow to run (mandatory)

the list of object ids to pass to the workflow (optional)

the parameters string, in format "name1:value1;name2:value2;..." (optional)

the list of the client paths of the dropped files (optional)

a callback method to call when the workflow ends (optional)

Overriding the OnDropExternal method like in the above example, the user has no clue that the workflow is over (successfully or with errors).

To process the workflow results and errors, we can configure a callback method, that is a method called when the workflow ends.

In the following example, we configure a callback method which refresh the selected tab (if any) and shows the error message if the workflow failed:

  Public Overrides Function OnDropExternal(ByVal droppedFiles As String()) As Boolean

    If Not droppedFiles Is Nothing AndAlso droppedFiles.Count > 0 Then

      'upload the files to the server and call the workflow

 

      'set the method to be called when the workflow ends. It must have the same signature than ExecuteWorkflowCallback.

      Dim callback = New ApplicationBase.ExecuteWorkflowCallback(AddressOf MyCallBack)

      'set the folder where the GN4 objects will be created

      Dim parameters As Specialized.NameValueCollection = New Specialized.NameValueCollection()

      parameters.Add("folderPath", EditorialLogin.GetLogin.GetContextObj()?.HomeFolderPath)

      'execute the workflow

      App.ExecuteWorkflowNoDialog("ImportActivityData", Nothing, parameters, droppedFiles, callback)

      Return true

    End If

    Return False

  End Function

 

  Public Sub MyCallBack(workflowName As String, wfResult As GNClient.WFResult)

    Try

      'refresh the visible list (if any)

      If ShellWindow.Tabs.GetTabCount() > 0 Then

        'refresh visually from a different thread

        ShellWindow.Window.Dispatcher.Invoke(DirectCast(

          Sub()

            Try

              ShellWindow.Tabs?.SelectedTab?.Refresh

            Catch ex As Exception

              MsgBox(ex.Message, Nothing, String.Format("Workflow '{0}'", workflowName))

            End Try

          End Sub, System.Action), System.Windows.Threading.DispatcherPriority.Normal)

      End If

 

      'read the workflow result

      Dim msg As System.Text.StringBuilder = New System.Text.StringBuilder()

      If wfResult IsNot Nothing Then

        If wfResult.HasErrors AndAlso wfResult.Log IsNot Nothing Then

          For Each log As GNClient.WFLogEntry in wfResult.Log

            If log.Code = CInt(TeraDP.GN4.Workflow.LogEntry.LogCode.Error) Then

              msg.AppendLine(String.Format("Error: {0}", log.Message))

            End IF

          Next

          'Else If wfResult.ImportResults IsNot Nothing Then

          'For Each res As GNClient.XmlImportResult in wfResult.ImportResults

          '  If res.IsNew Then

          '    msg.AppendLine(String.Format("Created {0} (id: {1})", res.ObjectType, res.ObjectId))

          '  End If

          'Next

        End If

      End If

      If msg.Length > 0 Then

        Dim message As String = Nothing

        If msg.ToString().Length > 1024 Then

          message = msg.ToString().Substring(0, 1024) & "..."

        Else

          message = msg.ToString()

        End If

        MsgBox(message, Nothing, String.Format("Workflow '{0}'", workflowName))

      End If

    Catch ex As Exception

      MsgBox(ex.Message, Nothing, String.Format("Workflow '{0}'", workflowName))

    End Try

  End Sub

 

Note that the callback method ("MyCallBack") can have any name, but it MUST have the same signature of the ApplicationBase.ExecuteWorkflowCallback method.

That is, the callback method must receive these two parameters: the name of the executed workflow and the GNClient.WFResult object, which contains the workflow result (like the error messages).

We can retrieve the ids of the GN4 objects created (or modified) by the workflow from the WFResult.ImportResults data (see the commented part of the above example).

To try the above example:

1.Open the Shell tab in Ted4.

2.Do a search by images.

3.Drag&drop pictures onto the result list: after a little time, we should see the pictures automatically added to the list.

You can execute workflows without interaction also from the menus.

In MainAddIn class (Shell.vb file of ShellSystemAddIn) there are two new script methods: ExecuteWorkflowNoDialog and ExecuteWorkflowNoDialogOnObjects.

These new methods accepts the string containing the data needed to execute the workflow (just like the already existing methods ExecuteWorkflow and ExecuteWorkflowOnObjects, that open the workflow panel).

Configure client software to run no-prompt workflows

You can configure the Ted4 menus to run workflows without interaction, with the standard syntax:

<l:ShellMenuItem Header="Run My Batch Workflow" CommandParameter="ExecuteWorkflowNoDialog" Parameters="wf=myWorkflowName&pars=name1:value1;name2:value2;" />

<l:ShellMenuItem Header="Run My Batch Workflow On Objects" CommandParameter="ExecuteWorkflowNoDialogOnObjects" Parameters="wf=myWorkflowName&pars=name1:value1;name2:value2;" />

 

By default, the script methods ExecuteWorkflowNoDialog and ExecuteWorkflowNoDialogOnObjects have a callback method ("ExecuteWorkflowNoDialogCallBack") which shows the workflow error (if any); however, they can be overridden in the custom scripts.

Note that all these new 'no-interaction' methods don't replace the good old Upload activity in the workflow panel.

About progress bar

If we want to show the progressing message to the user while Ted4 is uploading the files, we can use the standard OnDropExternal() method, that opens the workflow panel and shows the uploading controls.

About 'ForceNext'

To reduce the user interaction also in this scenario, a new property (called 'ForceNext') has been added to the Upload activity: if set to true, the 'Next' button is automatically clicked when all the files have been successfully uploaded to the server.

To try this new property, re-import the wf_UploadFirst.xml workflow and drag&drop files in Ted.