This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Script Error - The filename, directory name, or volume label syntax is incorrect

Hi,

I have also raised this issue with support. I created a script in a workflow tied to an external mail source consumption. This script has been working without error since September. On saturday, the script started throwing this error and I'm unsure why as nothing has changed. The error and my code are below.

M-Files Online
Kage {64CC5EF0-59F1-444C-BDD5-D237DB42471E}

Processing the contents of the external source "helpdesk@kageinnovation.com (outlook.office365.com)" failed.
The filename, directory name, or volume label syntax is incorrect.

ExternalFileMonitor.cpp, 7034, Processing the contents of the external source "helpdesk@kageinnovation.com (outlook.office365.com)" failed. (0x8004009F)
ExternalFileMonitor.cpp, 7034, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 446, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 628, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
MCallInLoop.h, 712, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 1571, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 1664, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 1828, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 3544, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 5513, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
ExternalFileMonitor.cpp, 5274, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 27866, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 2909, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 3121, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 3541, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 4380, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 274, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 339, Script execution failed. ((New or Existing Ticket_Help Desk Ticket Workflow, StateAction: 440-1229-1)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 339, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
VaultScriptSessionTemplates.cpp, 522, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
CoActiveScriptSite.cpp, 895, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
CoActiveScriptSite.cpp, 737, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
New or Existing Ticket_Help Desk Ticket Workflow, StateAction, 33, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
CoVaultObjectFileOperations.cpp, 537, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
CoVaultObjectFileOperations.cpp, 511, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
ServerVaultObjectFileOperationsHelper.cpp, 209, The filename, directory name, or volume label syntax is incorrect. (0x8007007B)
(M-Files 21.12.10943.6)

Option Explicit

Dim objClassID: objClassID = Vault.ObjectPropertyOperations.GetProperty (objver,100).Value.GetValueAsLookup.DisplayID

If objClassID = 10524 then

Dim i, txFileTitle, tmpFolder, d, txExistingFileTitle, txNewFileTitle, myObjVer, c, ext
Dim ObjVerName: ObjVerName = PropertyValues.SearchForProperty(2455).TypedValue.DisplayValue 'name of the object
Dim MyString: MyString = PropertyValues.SearchForProperty(2456).TypedValue.DisplayValue 'Email Subject property which inherits the email subject line
MyString = FXDeleteCharFromString(MyString)


On Error Resume Next ' the Instr commands below may not find with they are looking for, so we just turn off error handling for the next line of code. We check it's validity in the next IF.
Dim ExistingHelpDeskID: ExistingHelpDeskID = Replace(Mid(MyString, 1 + Instr(MyString,"["), Instr(MyString,"]") - Instr(MyString,"[") - 1), "HD", "") 'search for a meaningfull id in the property that pulls in the email subject line
on error goto 0


If IsNumeric(ExistingHelpDeskID) = True and LEN(ExistingHelpDeskID) > 1 then ' check to make sure the ID is numeric and it did not error out when parsing from the email subject line
	Set ExistingHelpDeskID = SearchForAnObject(ExistingHelpDeskID, False, "Help Desk Ticket")
	If ExistingHelpDeskID.Count > 0 Then 'this means that it found a match from the id in the subject line to a Help Desk Ticket in the vault.
		
			'find a matching title of the email subject line, ignoring the "RE", "FW" prefixes when looking for a match
			'tmpFolder = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%Temp%")
			tmpFolder = "C:\Windows\Temp"
			Set myObjVer = Vault.ObjectOperations.CheckOut(ExistingHelpDeskID.Item(1).ObjVer.Objid).ObjVer
			'save the files from this new email and attachments onto a temp location on the server to be transferred to the existing object in M-Files
			For Each i in Vault.ObjectFileOperations.GetFiles(ObjVer)
				txNewFileTitle = FXDeleteCharFromString(i.Title)
				'err.raise mfscriptcancel, txNewFileTitle
				if i.Extension = "msg" then txNewFileTitle = MyString
				ext = i.Extension
				'err.raise mfscriptcancel, tmpFolder & "\" & txNewFileTitle & "." & ext
				Vault.ObjectFileOperations.Downloadfile i.ID, i.Version, tmpFolder & "\" & txNewFileTitle & "." & ext
				
				For each d in Vault.ObjectFileOperations.GetFiles(myObjVer) ' gets the files of the Help Desk Object it found as a match to the email subject 
					txExistingFileTitle = d.Title 'existing file title
					if UCase(txExistingFileTitle) = UCase(txNewFileTitle) Then exit for
				Next
			if UCase(txExistingFileTitle) = UCase(txNewFileTitle) Then
				Vault.ObjectFileOperations.UploadFile d.ID, d.Version, tmpFolder & "\" & txNewFileTitle & "." & ext ' pulls file from temp folder and overwrites the existing file in the existing warranty consdiration with a matching title to the subject line, less the RE: and FW:
				'err.raise mfscriptcancel, tmpFolder & "\" & txNewFileTitle & "." & ext
				CreateObject("Scripting.FileSystemObject").DeleteFile(tmpFolder & "\" & txNewFileTitle & "." & ext) ' delete file from temp folder
			Else
				Vault.ObjectFileOperations.AddFile myObjVer, txNewFileTitle, ext, tmpFolder & "\" & txNewFileTitle & "." & ext 'tmpFolder & "\" & txNewFileTitle & ext ' add new file to existing warranty claim if there is no existing file title to match the email subject line
				'err.raise mfscriptcancel, tmpFolder & "\" & txNewFileTitle & "." & ext
				'CreateObject("Scripting.FileSystemObject").DeleteFile(tmpFolder & "\" & txNewFileTitle & "." & ext)
				 ' delete file from temp folder
			End if
			Next
			
			If Vault.ObjectPropertyOperations.GetProperty(myobjver, 39).value.displayvalue = "Closed_Help Desk Ticket Workflow" then
				Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
				oPropVal.PropertyDef = 2442
				oPropVal.TypedValue.SetValue MFDatatypeBoolean, ""				
				Vault.ObjectPropertyOperations.SetProperty myObjVer, oPropVal
				
				Call ChangeState(10650, myobjver)
			else
				Call ChangeState(10647, myobjver)
			end if
			
			Vault.ObjectOperations.CheckIn(myObjVer)
			Call ChangeState(10646, ObjVer)		
			
	else
	Call ChangeState(10626, ObjVer) ' Set the workflow state to Initial Notification
	end if
Else 
	Call ChangeState(10626, ObjVer) ' Set the workflow state to Initial Notification
End if

end if

'Functions Below
'===============================================================================================

Function ChangeState(iStateID, obObjVer)
' Set the workflow state to something
	Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
	oPropVal.PropertyDef = 39 ' Workflow states build-in property
	oPropVal.TypedValue.SetValue MFDatatypeLookup, iStateID
	Vault.ObjectPropertyOperations.SetProperty obObjVer, oPropVal
End Function


Function SearchForAnObject (txID, pDeleted, txClassName) 
	'txID as the textual value of the ID of the object you want to find
	'pDeleted as Boolean for deleted or not
	'txClassName as the textual name of the class you want to find

	'Set up values to perform a search
	Dim SC : Set SC = CreateObject("MFilesAPI.SearchCondition")
	Dim SCS : Set SCs = CreateObject("MFilesAPI.SearchConditions")
	Dim TV : Set TV = CreateObject("MFilesAPI.TypedValue")
	Dim Ex : Set Ex = CreateObject("MFilesAPI.Expression")

	'Set up places to hold the search results. results is just a collection.
	'Property 1
	TV.SetValue MFDatatypeText, txID
	Ex.DataStatusValueType = MFilesAPI.MFStatusType.MFStatusTypeExtID
	SC.Set Ex, MFConditionTypeEqual, TV	
	SCs.Add -1, SC
	'Deleted or not
	TV.SetValue MFilesAPI.MFDatatype.MFDatatypeBoolean, pDeleted
	Ex.DataStatusValueType = MFilesAPI.MFStatusType.MFStatusTypeDeleted	
	SC.Set Ex, MFConditionTypeEqual, TV	
	SCs.Add -1, SC
	'Class = 100, variable defines class "Name"
	Ex.SetPropertyValueExpression 100, MFilesAPI.MFParentChildBehavior.MFParentChildBehaviorNone, Nothing
	TV.SetValue MFDatatypeText, txClassName
	SC.Set Ex, MFConditionTypeEqual, TV
	SCs.Add -1, SC
	
	'Returns ObjectSearchResults Collection of objects
	Set SearchForAnObject = Vault.ObjectSearchOperations.SearchForObjectsByConditions(SCs, MFSearchFlagNone, False)
End Function






Function FXDeleteCharFromString(str)
	Dim charArray: charArray = Array("\","/","*","?","'","<",">","|")
	Dim replyArray: replyArray = Array("FW: ", "RE: ", "FW:", "RE:", "FWD: ", "FWD:")
	Dim a
	FXDeleteCharFromString = str
	For each a in charArray
		FXDeleteCharFromString = Replace (FXDeleteCharFromString, a, "_")
	Next
	For each a in replyArray
		FXDeleteCharFromString = Replace (ucase(FXDeleteCharFromString), a, "")
	Next
End Function

Parents
  • It looks like the path you're providing to the "DownloadFile" method is invalid.  It's hard to be sure without debugging the value.  The error is thrown on line 33.

    I started looking at the code for how the file name on disk is created.  It seems to be trying to strip various characters, but there seems to be at least one character that's allowed that shouldn't be (":"; I know that you strip out "RE:", etc., but the colon character on its own could be problematic).  Again: without debugging I can't see what exactly is wrong with the file name.  It could also be some sort of non-printable character or some other value that's not valid in a file name.

    Which leads me to a question: why are you generating the name yourself?  Could you not use GetNameForFileSystem?

  • I added an err.raise to grab value. This is what it shows:

    ID: 1088463 Version: 1 Path: C:\Windows\Temp\[HD306] INSTALL KEYBOARD.msg

  • Nothing there jumps out at me as invalid, although I suspect that a number of the characters listed here (Path.GetInvalidPathChars Method (System.IO) | Microsoft Docs) would be non-printable and not visible in your Err.Raise call.

    I can't currently see any tracker items related to that error message, so my gut instinct is still that the path you're providing is invalid in some way.

    I note that your code iterates through all the files but, obviously, Err.Raise will show you details of the first one.  Could it be that a second, third, or other such file is the one that is causing the issue?

Reply
  • Nothing there jumps out at me as invalid, although I suspect that a number of the characters listed here (Path.GetInvalidPathChars Method (System.IO) | Microsoft Docs) would be non-printable and not visible in your Err.Raise call.

    I can't currently see any tracker items related to that error message, so my gut instinct is still that the path you're providing is invalid in some way.

    I note that your code iterates through all the files but, obviously, Err.Raise will show you details of the first one.  Could it be that a second, third, or other such file is the one that is causing the issue?

Children
  • I put the err.raise right before the line where it downloads the file. It already does all of the checks beforehand and this will be the only file for the current iteration of the script. I'll do some more detailed investigation and let you know what I find.

  • Does the object get added to M-Files?  I guess not, as the script failing is stopping the object being added.

    Part of me wants to allow the object to be entered into M-Files but for the script to not run.  Then run the script manually (move the object into the workflow state) and see whether being able to easily see the actual object/file that's failing will assist in working out what the issue is.

  • So, it is building the file path based on the email subject. The only variable is the email subject.

    tmpFolder & "\" & txNewFileTitle & "." & ext

    I tested multiple emails by moving the one that was failing to another folder in the inbox. These are the 2 subject lines from the list of emails that were having issues:

    Re: [HD306] Install keyboard

    Fwd: Form submission from: Technical Support : NVR Ticket Number 672932 [HD384]

    I'll have to dig into which characters are causing the problem in both. Once the two emails were moved to a different folder, M-Files consumed the rest of the emails.

  • As I said in my original email: your current code doesn't strip colons.  The second email title has two colons that would not be stripped ("from: " and " Support : NVR").  Either of those would cause your code to produce an invalid file path.

    Why are you trying to strip the data yourself and not, instead, using the "GetNameForFileSystem" method that'll do all this for you?

  • I was able to get this to work. The reason I am not using GetNameForFileSystem is because an existing email with the same subject may not already exist on the object. When it doesn't exist we want to add a new file with whatever the email subject was. Ideally all emails related to an object will have the same title, but that may not always be the case and we would not want to overwrite the existing email in that case. 

    Based on this link you provided and the insights you offered, I was able to modify the below procedure in my code and everything is now working.

    Nothing there jumps out at me as invalid, although I suspect that a number of the characters listed here (Path.GetInvalidPathChars Method (System.IO) | Microsoft Docs) would be non-printable and not visible in your Err.Raise call.

    Original:

    Function FXDeleteCharFromString(str)
    	Dim charArray: charArray = Array("\","/","*","?","'","<",">","|")
    	Dim replyArray: replyArray = Array("FW: ", "RE: ", "FW:", "RE:", "FWD: ", "FWD:")
    	Dim a
    	FXDeleteCharFromString = str
    	For each a in charArray
    		FXDeleteCharFromString = Replace (FXDeleteCharFromString, a, "_")
    	Next
    	For each a in replyArray
    		FXDeleteCharFromString = Replace (ucase(FXDeleteCharFromString), a, "")
    	Next
    End Function

    Updated:

    Function FXDeleteCharFromString(str)
    	Dim charArray: charArray = Array("\","/","*","?","'","<",">","|",":")
    	Dim replyArray: replyArray = Array("FW: ", "RE: ", "FW:", "RE:", "FWD: ", "FWD:")
    	Dim a
    	FXDeleteCharFromString = str
    	For each a in replyArray
    		FXDeleteCharFromString = Replace (ucase(FXDeleteCharFromString), a, "")
    	Next	
    	For each a in charArray
    		FXDeleteCharFromString = Replace (FXDeleteCharFromString, a, "_")
    	Next
    
    End Function