The script could not be executed because the maximum number of nested scripts was exceeded

Hello guys,

For the context : I would like to know who was the last person who changed a certain property.

For this, I created an Event Handler (AfterSetProperties) where I get my current user and check if the property was changed based on its previous version

Option Explicit

' Get the required properties for this script
Const CLASS_PROPERTY = 100 'Class Property
CONST EMPLOYES = 1420
CONST USER_TEST = 1549
Const DOCUMENT_OBJECTTYPE = 0  ' Document Object Type

Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True )

'If the object is a document and belongs to the "Document test" class
if( ObjVer.Type = DOCUMENT_OBJECTTYPE) and (PropertyValues.SearchForProperty(CLASS_PROPERTY).TypedValue.DisplayValue = "Document test") then

Dim employesDisplayValue : employesDisplayValue = PropertyValues.SearchForProperty(EMPLOYES).TypedValue.DisplayValue

	if NOT(employesDisplayValue="" AND ObjVer.Version > 1) then	
		dim previousVersion : previousVersion = (ObjVer.Version - 1)
		Dim newObjVer : set newObjVer = CreateObject("MFilesAPI.ObjVer")
		newObjVer.SetIDs 0, ObjVer.ID, previousVersion
		
		Dim previousProperties : set previousProperties = Vault.ObjectOperations.GetObjectVersionAndProperties(newObjVer).Properties
	
		dim previousEmployes : previousEmployes = previousProperties.SearchForProperty(EMPLOYES).TypedValue.DisplayValue
	
		if NOT(employesDisplayValue=previousEmployes)then
	
			Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
			oLookup.Item = currentUserID
			oLookup.ObjectType = 6
	
			Dim propValLoggedUser : Set propValLoggedUser = CreateObject("MFilesAPI.PropertyValue")
			propValLoggedUser.PropertyDef = USER_TEST	
			propValLoggedUser.TypedValue.SetValueToLookup oLookup
			Vault.ObjectPropertyOperations.SetProperty ObjVer, propValLoggedUser
		end if
	end if
End if

When i'm testing the script, I'm getting this error : 

  • AfterSetProperties::DocumentTestModifiedBy, 36, The script could not be executed because the maximum number of nested scripts was exceeded. (0x80040969)

I've already checked the execution order : https://www.m-files.com/user-guide/2018/eng/execution_order_of_scripts.html and i'm pretty sure that's the event handler i need to use.

Any help will be very appreciated Slight smile

Thank you very much
Claudio - EVOK - Altern8 SA

Parents
  • It is possible to increase the maximum number of scripts in Advanced Vault settings, but be careful and only increase in modest numbers if you are absolutely certain that is what you need. Otherwise you may allow the server to run endlessly if your scripting leads to a loop.

    I have not checked your code for errors!

Reply
  • It is possible to increase the maximum number of scripts in Advanced Vault settings, but be careful and only increase in modest numbers if you are absolutely certain that is what you need. Otherwise you may allow the server to run endlessly if your scripting leads to a loop.

    I have not checked your code for errors!

Children
No Data