Script Execution Failed

Hi there,

I hope everyone had a good Xmas and New Year!

There is a script below added in a workflow. This script has been working without error until last upgrade was happened. It started throwing the error when trying the last step of the workflow (Publish to PDF) and we’re unsure why as nothing has been changed. Below are the error message and WF Script. Can you please assist?

Not Found

<MetadataEditor>, -, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
ScriptErrorHelper.cpp, 96, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MDispatchExImpl.h, 679, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MDispatchExImpl.h, 841, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MetadataCardAction.cpp, 386, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MetadataCardAction.cpp, 560, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MetadataEditor.cpp, 2956, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MetadataModel.cpp, 4488, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MetadataModel.cpp, 4939, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
ElectronicSignatureUIHelper.cpp, 239, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MetadataModel.cpp, 12646, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
CoVaultMountingDocumentOperations.cpp, 3296, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
CoVaultMountingDocumentOperations.cpp, 3384, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
DocumentCache.cpp, 11824, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
DocumentCache.cpp, 11935, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
DocumentCache.cpp, 20364, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
IRPCObjectOperations.generated.cpp, 12120, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
gRPCClient.cpp, 497, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
gRPCClient.cpp, 466, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
gRPCClient.cpp, 99, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
gRPC.generated.cpp, 19358, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperations.cpp, 7173, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
MCallInLoop.h, 530, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 4297, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 3855, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 9642, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 10363, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelper.cpp, 25667, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 2967, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 3184, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 3612, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
RPCDocumentOperationsHelperPrivate.cpp, 4487, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 276, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 341, Script execution failed. ((HSEQ Approved Document, StateAction: 470344-11)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 341, Not found. (0x8004000B)
VaultScriptSessionTemplates.cpp, 523, Not found. (0x8004000B)
CoActiveScriptSite.cpp, 897, Not found. (0x8004000B)
CoActiveScriptSite.cpp, 739, Not found. (0x8004000B)
HSEQ Approved Document, StateAction, 33, Not found. (0x8004000B)
MNullPropagatingDispatchImpl.h, 127, Not found. (0x8004000B)
MNullPropagatingDispatchImpl.h, 174, Not found. (0x8004000B)
CoPropertyValues.cpp, 394, Not found. (0x8004000B)
(M-Files 23.12.13247.4 2024-01-10T04:02:11.395Z)

'Purpose: Download HSEQ WIP document and recreate as a HSEQ Published document.
'	   

Option Explicit


	'Temp variables
	Const TEMP_PATH = "C:\Windows\Temp\ICC_M-Files\"
	Const ALLOWED_EXTENSIONS = "docx doc xls xlsx pptx ppt txt png jpg"

	'Get properties from HSEQ WIP document ready to copy to HSEQ Document
	Dim oPV_Name			: Set oPV_Name = PropertyValues.SearchForProperty(MFBuiltInPropertyDefNameOrTitle)
 	Dim oPV_HSEQCategory	: Set oPV_HSEQCategory = PropertyValues.SearchForPropertyByAlias(vault, "PD.HSEQCategory", False)
	Dim oPV_Subcategory		: Set oPV_Subcategory = PropertyValues.SearchForPropertyByAlias(vault, "PD.Subcategory", False)
	Dim oPV_DocumentDate	: Set oPV_DocumentDate = PropertyValues.SearchForPropertyByAlias(vault, "PD.DocumentDate", False)	
	Dim oPV_DescriptionNotes : Set oPV_DescriptionNotes = PropertyValues.SearchForPropertyByAlias(vault, "PD.DescriptionNotes", False)	


'  Due to changes - remove checked by and prepared by
 '	Dim oPV_PreparedBy	: Set oPV_PreparedBy = PropertyValues.SearchForPropertyByAlias(vault, "PD.PreparedBy", False)
'  	Dim oPV_CheckedBy	: Set oPV_CheckedBy = PropertyValues.SearchForPropertyByAlias(vault, "PD.CheckedBy", False)

	Dim oPV_Accountable	: Set oPV_Accountable = PropertyValues.SearchForPropertyByAlias(vault, "PD.Accountable", False)
 	Dim oPV_Responsible	: Set oPV_Responsible = PropertyValues.SearchForPropertyByAlias(vault, "PD.Responsible", False)
 	Dim oPV_FormattedBy	: Set oPV_FormattedBy = PropertyValues.SearchForPropertyByAlias(vault, "PD.FormattedBy", False)

 	Dim oPV_HSEQSubCategory	: Set oPV_HSEQSubCategory = PropertyValues.SearchForPropertyByAlias(vault, "PD.HSEQSubCategory", False)


 	Dim oPV_ApproveHSEQ	: Set oPV_ApproveHSEQ = PropertyValues.SearchForPropertyByAlias(vault, "PD.ApproveHSEQ", False)


 	Dim oPV_HSEQNo	: Set oPV_HSEQNo = PropertyValues.SearchForPropertyByAlias(vault, "PD.HSEQNo", False)

	Dim iPD_PublishedHSEQDoc : iPD_PublishedHSEQDoc = iGetIDFromAlias("PD.PublishedHSEQDoc")

	'Setup Properties for new HSEQ Document

	Dim iCLS_TargetClass : iCLS_TargetClass = Vault.ClassOperations.GetObjectClassIDByAlias("CLS.HSEQ")
	Dim iWF_TargetWF : iWF_TargetWF = Vault.WorkflowOperations.GetWorkflowIDByAlias("WF.HseqWorkflow")
	Dim iWFS_TargetWFS : iWFS_TargetWFS = Vault.WorkflowOperations.GetWorkflowStateIDByAlias("WFS.HseqWorkflow.PrepareToPublish")

	Dim oPV_TargetClass, oPV_TargetWF, oPV_TargetWFS
	Set oPV_TargetClass = PropertyValues.SearchForProperty(100)
	Set oPV_TargetWF = PropertyValues.SearchForProperty(38)
	Set oPV_TargetWFS = PropertyValues.SearchForProperty(39)

	Call oPV_TargetClass.TypedValue.SetValue(9, iCLS_TargetClass)
	Call oPV_TargetWF.TypedValue.SetValue(9, iWF_TargetWF)
	Call oPV_TargetWFS.TypedValue.SetValue(9, iWFS_TargetWFS)

	Dim strTempFileFullPath
	strTempFileFullPath = strDownlowdedFilePath(ObjVer.ObjID.ID, ALLOWED_EXTENSIONS)

	'Setup PropertyValues for new document

	Dim oPVs_NewDoc : Set oPVs_NewDoc = CreateObject("MFilesAPI.PropertyValues")


	Call oPVs_NewDoc.Add(-1, oPV_TargetClass)
	Call oPVs_NewDoc.Add(-1, oPV_TargetWF)
	Call oPVs_NewDoc.Add(-1, oPV_TargetWFS)

	Call oPVs_NewDoc.Add(-1, oPV_Name)

	Call oPVs_NewDoc.Add(-1, oPV_HSEQCategory)
	Call oPVs_NewDoc.Add(-1, oPV_Subcategory)

	Call oPVs_NewDoc.Add(-1, oPV_DocumentDate)
	Call oPVs_NewDoc.Add(-1, oPV_DescriptionNotes)

	Call oPVs_NewDoc.Add(-1, oPV_Accountable)
	Call oPVs_NewDoc.Add(-1, oPV_Responsible)
	Call oPVs_NewDoc.Add(-1, oPV_FormattedBy)

	Call oPVs_NewDoc.Add(-1, oPV_HSEQSubCategory)


	Call oPVs_NewDoc.Add(-1, oPV_ApproveHSEQ)
	Call oPVs_NewDoc.Add(-1, oPV_HSEQNo)


	'Add Published HSEQ Doc property if missing or empty
	Dim oNewVerObjAndProps

	Dim oPV_PublishedHSEQDoc : Set oPV_PublishedHSEQDoc = CreateObject("MFilesAPI.PropertyValue")
	If PropertyValues.IndexOf(iPD_PublishedHSEQDoc) <> - 1 then 'if not missing
		
		If PropertyValues.SearchForProperty(iPD_PublishedHSEQDoc).TypedValue.IsNull OR Instr(PropertyValues.SearchForProperty(iPD_PublishedHSEQDoc).TypedValue.DisplayValue, "deleted") > 0 then 'if empty or Null or Deleted

			'Create new Published Document
			Set oNewVerObjAndProps = Vault.ObjectOperations.CreateNewSFDObject(MFBuiltInObjectTypeDocument, oPVs_NewDoc, oSourceFile_FromPath(strTempFileFullPath), False, Nothing)
			Call Vault.ObjectOperations.CheckIn(oNewVerObjAndProps.ObjVer)
	
			'Setup link to Published HSEQ Document and Add
			oPV_PublishedHSEQDoc.PropertyDef = iPD_PublishedHSEQDoc
			Call oPV_PublishedHSEQDoc.TypedValue.SetValue(9, oNewVerObjAndProps.ObjVer.ID) 
			Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPV_PublishedHSEQDoc)

		Else 'If link to Published Document exists then update it

			Dim oLU_PubHSEQDoc
			Set oLU_PubHSEQDoc = PropertyValues.SearchForProperty(iPD_PublishedHSEQDoc).TypedValue.GetValueAsLookup

			Dim oObjID_PubHSEQDoc : Set oObjID_PubHSEQDoc = CReateObject("MFilesAPI.ObjID")
			Call oObjID_PubHSEQDoc.SetIDs(oLU_PubHSEQDoc.ObjectType, oLU_PubHSEQDoc.Item)
			
			Dim oObjectVersion_PubHSEQDoc 
			Set oObjectVersion_PubHSEQDoc = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(oObjID_PubHSEQDoc, False, False).VersionData

			Call UpdateExistingDocument(oObjectVersion_PubHSEQDoc, strTempFileFullPath, oPVs_NewDoc)


		End If

	Else 'If missing then add.


		'Create new Published Document

'Call oSourceFile_FromPath(strTempFileFullPath)


		Set oNewVerObjAndProps = Vault.ObjectOperations.CreateNewSFDObject(MFBuiltInObjectTypeDocument, oPVs_NewDoc, oSourceFile_FromPath(strTempFileFullPath), False, Nothing)
		Call Vault.ObjectOperations.CheckIn(oNewVerObjAndProps.ObjVer)

		oPV_PublishedHSEQDoc.PropertyDef = iPD_PublishedHSEQDoc
		Call oPV_PublishedHSEQDoc.TypedValue.SetValue(9, oNewVerObjAndProps.ObjVer.ID) 

		Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPV_PublishedHSEQDoc)

	End If

	Call DeleteFileInPath(strTempFileFullPath)

			

'===================================================================================


Sub DeleteFileInPath(strFilePath)
'Where strFilePath is the full path including filename and extension.

	Dim oFSO  ' Windows file system object
	Set oFSO = CreateObject("Scripting.FileSystemObject")

	Call oFSO.DeleteFile(strFilePath)

End Sub



'Get oSourceFile from full path to file.
Function oSourceFile_FromPath(strFullPath)

	Dim oFSO  ' Windows file system object
	Set oFSO = CreateObject("Scripting.FileSystemObject")

	If oFSO.FileExists(strFullPath) Then

	Dim strFullTitleWithExt, strTitle, strExt, strPath, arrPaths

	arrPaths = Split(strFullPath, "\")

	strFullTitleWithExt = arrPaths(UBound(arrPaths))

    'Strip of file extension allowing form more than one '.'
	strTitle = Left(strFullPath,InStrRev(strFullPath,".")-1)

	strPath = Replace(strFullPath, "\" & strFullTitleWithExt, "")

	strExt = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath,"."))


	Dim oSourceFile
	Set oSourceFile = CreateObject("MFilesAPI.SourceObjectFile")
	oSourceFile.Title = strTitle
	oSourceFile.Extension = strExt
	oSourceFile.SourceFilePath = strFullPath

	Set oSourceFile_FromPath = oSourceFile
	
	Else
		Die("Warning: Subject file missing on server [" & strFullPath & "]")	
	End If  ' If Temp file creation succeeded

End Function


'Get the ID of the Alias
Function iGetIDFromAlias(strAlias)
 
	strAlias = Trim(strAlias)

	If IsNumeric(strAlias) then 
	
		iGetIDFromAlias = Clng(strAlias)

	Else

		IF Instr(strAlias, "PD.") > 0 OR Instr(strAlias, "PD_") then iGetIDFromAlias = vault.PropertyDefOperations.GetPropertyDefIDByAlias(strAlias)
		IF Instr(strAlias, "OT.") > 0 OR Instr(strAlias, "OT_") > 0 then iGetIDFromAlias = vault.ObjectTypeOperations.GetObjectTypeIDByAlias(strAlias)
		IF Instr(strAlias, "CLS.") > 0 OR Instr(strAlias, "CLS_") then iGetIDFromAlias = vault.ClassOperations.GetObjectClassIDByAlias(strAlias)
		IF Instr(strAlias, "WF.") > 0 OR Instr(strAlias, "WF_") then iGetIDFromAlias = vault.WorkflowOperations.GetWorkflowIDByAlias(strAlias)
		IF Instr(strAlias, "WFS.") > 0 OR Instr(strAlias, "WFS_") then iGetIDFromAlias = vault.WorkflowOperations.GetWorkflowStateIDByAlias(strAlias)
		IF Instr(strAlias, "GRP.") > 0 OR Instr(strAlias, "GRP_") > 0 then iGetIDFromAlias = vault.UserGroupOperations.GetUserGroupIDByAlias(strAlias)
		IF Instr(strAlias, "NACL.") > 0 OR Instr(strAlias, "NACL_") > 0 then iGetIDFromAlias = vault.NamedACLOperations.GetNamedACLIDByAlias(strAlias)

		if iGetIDFromAlias = -1 or iGetIDFromAlias = 0 then Die("Could not obtain ID from Alias. [" & strAlias & "]")

	End If

End Function

Function Die(strMessage)
	err.raise mfscriptcancel, strMessage
End Function

Sub SetLastModUser()
	' Set last modified by with TypedValue
	Dim oLastModifiedBy : Set oLastModifiedBy = CreateObject("MFilesAPI.TypedValue")
	oLastModifiedBy.SetValue MFDatatypeLookup, CurrentUserID
	Call Vault.ObjectPropertyOperations.SetLastModificationInfoAdmin(ObjVer, True, oLastModifiedBy, False, Nothing)
End Sub


' Returns the PropertyValue object of a key property of a related object 
Function oGetPropValOFPropOfRelatedObject(iOT_REL_OBJECT, iPD_REL_OBJECT, iPD_KEY_PROP) 
    
	Dim oPropVals: Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)

	' Find ID of Related Object	
	Dim oRelObjTypedValue : oRelObjTypedValue = oPropVals.SearchForProperty( iPD_REL_OBJECT ).TypedValue.Value
	Dim iRelObj : iRelObj = oRelObjTypedValue(0,0)

	'Set ObjID of Related Object
	Dim oRelObjID : Set oRelObjID = CreateObject("MFilesAPI.ObjID")
	Call oRelObjID.SetIDs(iOT_REL_OBJECT, iRelObj)

	'Get latest ObjVer for RelObj
	Dim oRelObjVer : Set oRelObjVer = Vault.ObjectOperations.GetLatestObjVer(oRelObjID, False, False)

	'Get KEY PROP from Related Object
	Dim oPropValsRel : Set oPropValsRel = Vault.ObjectPropertyOperations.GetProperties(oRelObjVer, iPD_KEY_PROP)
	
	'Prep PropValue Object
	Dim oPropValFn
    If oPropValsRel.IndexOf(iPD_KEY_PROP) = -1 then ' Check if property associated to object

		Set oPropValFn = CreateObject("MFilesAPI.PropertyValue")
		Call oPropValFn.TypedValue.SetValue(MFDataTypeText, "") ' Set empty property to return

	Else
       
		Set oPropValFn = oPropValsRel.Item(oPropValsRel.IndexOf(iPD_KEY_PROP)) ' Return PropertyValue
		
	End IF
	
	Set oGetPropValOFPropOfRelatedObject = oPropValFn

End Function

'Download a single file with allowed extension and return full path
Function strDownlowdedFilePath(iID_Document, strAllowedExtensions)

'PreReqs TEMP_PATH should be set somewhere in "c:\windows\temp\"
'        AllowedExtensions added with space between if more than one.

	'Create ObjVer for TargetDocID
	Dim oObjID_TargetDoc : Set oObjID_TargetDoc = CreateObject("MFilesAPI.ObjID")
	Call oObjID_TargetDoc.SetIDs(MFBuiltInObjectTypeDocument, iID_Document)

		Dim oObjVer_TargetDoc
		Set oObjVer_TargetDoc = Vault.ObjectOperations.GetLatestObjVer(oObjID_TargetDoc, True, False)

	' Get the object files
	Dim oObjectFiles_TargetDoc
	Set oObjectFiles_TargetDoc = Vault.ObjectFileOperations.GetFiles(oObjVer_TargetDoc)

	If oObjectFiles_TargetDoc.Count <> 1 then Die("Warning: Only a single file of the follwing types are allowed...[" & strAllowedExtensions & "]")

	'Die(TEMP_PATH)

	'If Instr(lcase(TEMP_PATH), "c:\windows\temp\") = 0 then Die("Warning: A TEMP_PATH under c:\windows\temp\ is required to be set...")

	Dim oFile

	For Each oFile in oObjectFiles_TargetDoc 

		'File extension test
		If Instr(strAllowedExtensions, lcase(oFile.extension)) > 0 then

			Dim oFSO  ' Windows file system object
			Set oFSO = CreateObject("Scripting.FileSystemObject")
			
			' Try to create a temp folder
			On Error Resume Next
			oFSO.CreateFolder(TEMP_PATH)

			On Error Goto 0   

			Dim szDownloadLocation ' PDF-file will be downloaded to temp path		
			szDownloadLocation = TEMP_PATH & oObjVer_TargetDoc.ID & "_" & oFile.ID & "_" & oFile.Version & "." & oFile.extension

			' Download file to temp location
			Vault.ObjectFileOperations.DownloadFile oFile.ID, oFile.Version, szDownloadLocation

		Else

			Die("Warning: Only a single file of the follwing types are allowed...[" & strAllowedExtensions & "]")

		End If 'File Extension Test

	Next

	If szDownloadLocation <> "" then strDownlowdedFilePath = szDownloadLocation

End Function


'Update file with specified ObjectVersion and full path of file
Sub UpdateExistingDocument(ooObjectVersion, strFileInDownLoadPath, oPVs_ForUpdate)

	'iTargetWFS should be 0 for no change or the WFS ID Number
	Dim strExt

	If Left(Right(strFileInDownLoadPath, 4),1) = "." OR Left(Right(strFileInDownLoadPath, 5),1) = "." then
		If Left(Right(strFileInDownLoadPath, 4),1) = "." then strExt = Right(strFileInDownLoadPath, 3)
		If Left(Right(strFileInDownLoadPath, 5), 1) = "." then strExt = Right(strFileInDownLoadPath, 4)
	Else 

		err.raise mfscriptcancel, "File extension could not be determined from path..." & strFileInDownLoadPath

	End If


	Dim ooCheckedOutObjectVersion
	Set ooCheckedOutObjectVersion = Vault.ObjectOperations.Checkout(ooObjectVersion.ObjVer.ObjID)

	' Determine the target file to be uploaded.
	Dim oCheckedOutFiles
	Dim oCheckedOutFile
	Set oCheckedOutFiles = Vault.ObjectFileOperations.GetFiles(ooCheckedOutObjectVersion.ObjVer)
	Set oCheckedOutFile = oCheckedOutFiles.Item(1)


	' Upload the file.
	Call Vault.ObjectFileOperations.UploadFile(oCheckedOutFile.ID, oCheckedOutFile.FileVer.Version, strFileInDownLoadPath)



	Call Vault.ObjectFileOperations.RenameFile(ooCheckedOutObjectVersion.ObjVer, oCheckedOutFile.FileVer, ooCheckedOutObjectVersion.Title, strExt, True)

	'If PVs are available then update
	If NOT IsNUll(oPVs_ForUpdate) then
		If oPVs_ForUpdate.Count > 0 then
	
			'Remove Class PV if present
			If oPVs_ForUpdate.IndexOf(100) <> -1 then oPVs_ForUpdate.Remove(oPVs_ForUpdate.IndexOf(100))

			Call Vault.ObjectPropertyOperations.SetProperties(ooCheckedOutObjectVersion.ObjVer, oPVs_ForUpdate)
	
		End If
	End If


	' Finalize with check-in.
	Call Vault.ObjectOperations.CheckIn(ooCheckedOutObjectVersion.ObjVer)
 
End Sub
'=========================

Thank you