Handling hub vault unavailability
The NextDocumentName function and DocGenericEvent_AfterNewDocument event handler described in the preceding topics will fail when the hub vault is not available online for any reason. If this happens, the functions will try to give the document an empty name, which will result in an error. To resolve this problem, the VBScript code should be modified to generate a temporary document name (for example, TMP-nnnnn) when the hub vault is not available. In the following examples, when a document has a temporary name, a new attempt will be made to retrieve the permanent name after each workflow state change.
The following changes should be made to the code:
- The document naming moved to a separate procedure.
- The document naming function detects when it did not receive a document name from the central vault and generates a temporary name instead.
- The document naming function is also called from the event handlers for workflow state changes.
The following example shows a wrapper around the NextDocumentName function to assign a temporary document name if the hub vault is unresponsive.
Sub SetDocumentName
Set objGCF = AMCreateObject ("BlueCieloECM.GcfSupport", False)
v = Document.DocumentType.DisplayName
'The next statement avoids the error dialog that would otherwise appear 'when an error occurs during the remote call. On Error Resume Next
vFilename = objGCF.CallRemote "NumberVault", "NextDocumentName", Document.GlobalID, v)
Set objGCF = Nothing 'When the remote call fails for any reason, return no result
If vFilename = "" Then
If Left(Document.Filename, 3) = "TMP" Then 'If the document already has a temporary name and the remote call fails again, 'it should not get a new temporary name.
Exit Sub
Else
vFilename = "TMP-" & Right ("00000" & Vault.Sequence ("Temporary").Next, 5)
End If
End If
Document.Filename = vFilename & ".Txt"
End Sub
The DocGenericEvent_AfterNewDocument event handler is modified to call the SetDocumentName function in the following example:
Sub DocGenericEvent_AfterNewDocument (Batch, Action, SourceFile, DocType, DocTemplate)
GCFDocGeneric_AfterNewDocument Batch, Action, SourceFile, DocType, DocTemplate
Call SetDocumentName
End Sub
Finally, a call to SetDocumentName is added to the DocWorkflowEvent_AfterChangeWFState event handler as shown in the following example:
Sub DocWorkflowEvent_AfterChangeWFState (Batch, SourceState, _ destinationState, Person, Comment)
If Left(Document.Filename, 3) = "TMP" Then
Call SetDocumentName
End If
End Sub