The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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

Error trying to edit object during BeforeSetObjectPermission event handling

Hello.

I have a following task: "if there were added a specific usergroups to permissions of object then to clear a field of this object."

I created an eventhandler for event BeforeSetObjectPermissions, it is successfully triggering on adding of usergroups, but I am unable to clear the fields of object. Looks like it is not allowed to make changes in objects during BeforeSetObjectPermissions event handling. I am receiving the error "Operation not allowed. Script is being executed for the object "48". (0x80040834)" at the row with CheckOut or SetProperty function.

Is there any way to solve this problem?

Thank you!

Parents
  • So I haven't tried this myself before, but you should not need to check out the current object during an event handler; it should already be checked out.

    I'm not saying that this will definitely work, but the concept of checking the object out should not be needed.

    Do you get the same error thrown with just the SaveProperty call?  Can you show me the code you're trying and the full error stack?

  • Hi, Craig!

    I tried to make SetProperties alone as so as together to CheckIn and CheckOut and received the same error.

    Here is my reduced code (I made it for testing and it is also shows me an error "Operation not allowed. Script is being executed for the object")

    If ObjVer.Type = 0 then 
    
    	Dim newPropertyValues: Set newPropertyValues = CreateObject("MFilesAPI.PropertyValues")
    	Dim newPropertyValue:  Set newPropertyValue  = CreateObject("MFilesAPI.PropertyValue")
    
    	newPropertyValue.PropertyDef = 1044
    	newPropertyValue.TypedValue.SetValue MFDatatypeMultiLineText, "121212"
    	newPropertyValues.Add -1, newPropertyValue
    
    	Vault.ObjectPropertyOperations.SetProperties ObjVer, newPropertyValues '<< Here the error occurs
    End if

    The full text of error:

    CoScriptObjectFactory.cpp, 465, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    ScriptErrorHelper.cpp, 96, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MDispatchExImpl.h, 694, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MDispatchExImpl.h, 994, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MetadataCardAction.cpp, 386, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MetadataCardAction.cpp, 570, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MetadataEditor.cpp, 2967, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MetadataModel.cpp, 4266, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MetadataModel.cpp, 4763, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    CoVaultMountingDocumentOperations.cpp, 3600, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    DocumentCache.cpp, 5954, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    DocumentCache.cpp, 6019, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    DocumentCache.cpp, 19901, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCMethodCallWithRetry.h, 28, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCMethodCallWithRetry.h, 28, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCDocumentOperations.cpp, 13190, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCDocumentOperations.cpp, 8120, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    MCallInLoop.h, 712, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 1417, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 1602, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 13413, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 25842, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    VaultDBSessionEvents.cpp, 428, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    VaultDBSessionEvents.cpp, 1602, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((AfterSetObjectPermissions::pep22: 48-47)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultScriptSessionTemplates.cpp, 501, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoActiveScriptSite.cpp, 893, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoActiveScriptSite.cpp, 735, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    AfterSetObjectPermissions::pep22, 49, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoVaultObjectPropertyOperations.cpp, 381, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoVaultObjectPropertyOperations.cpp, 406, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoVaultObjectPropertyOperations.cpp, 475, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    ServerVaultObjectPropertyOperationsHelper.cpp, 415, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCObjectOperationsHelper.cpp, 109, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoRPCOverCOM.cpp, 6153, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperations.cpp, 7384, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    MCallInLoop.h, 712, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 3930, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 3460, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelperPrivate.cpp, 10809, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 10495, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 11898, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultTrTrackerHelper.cpp, 425, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultTrTrackerHelper.cpp, 1118, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultTrTrackerHelper.cpp, 1323, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    (M-Files 21.4.10123.9)

  • The error message says that this is an "AfterSetObjectPermissions" event, not "before".  It also references line 49, but I can't see a line 49 in your posted code:

    AfterSetObjectPermissions::pep22, 49, Operation not allowed. Script is being executed for the object "48". (0x80040834)

    Can you confirm which event you're using?  "After" events generally cannot alter the object, but the "before" events generally can.

    Regards,

    Craig.

Reply
  • The error message says that this is an "AfterSetObjectPermissions" event, not "before".  It also references line 49, but I can't see a line 49 in your posted code:

    AfterSetObjectPermissions::pep22, 49, Operation not allowed. Script is being executed for the object "48". (0x80040834)

    Can you confirm which event you're using?  "After" events generally cannot alter the object, but the "before" events generally can.

    Regards,

    Craig.

Children
  • Hi Craig!

    Actually i already tried both of Before and After events and sent you result of the last used. I made the same using Before ebent and received this error:

    CoScriptObjectFactory.cpp, 465, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    ScriptErrorHelper.cpp, 96, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MDispatchExImpl.h, 694, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MDispatchExImpl.h, 994, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MetadataCardAction.cpp, 386, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MetadataCardAction.cpp, 570, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MetadataEditor.cpp, 2967, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MetadataModel.cpp, 4266, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MetadataModel.cpp, 4763, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    CoVaultMountingDocumentOperations.cpp, 3600, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    DocumentCache.cpp, 5954, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    DocumentCache.cpp, 6019, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    DocumentCache.cpp, 19901, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCMethodCallWithRetry.h, 28, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCMethodCallWithRetry.h, 28, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCDocumentOperations.cpp, 13190, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCDocumentOperations.cpp, 8120, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    MCallInLoop.h, 712, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 1417, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 1602, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 13413, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 25733, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    VaultDBSessionEvents.cpp, 428, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    VaultDBSessionEvents.cpp, 1602, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((BeforeSetObjectPermissions::test22: 48-47)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultScriptSessionTemplates.cpp, 501, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoActiveScriptSite.cpp, 893, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoActiveScriptSite.cpp, 735, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    BeforeSetObjectPermissions::test22, 50, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoVaultObjectPropertyOperations.cpp, 381, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoVaultObjectPropertyOperations.cpp, 406, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoVaultObjectPropertyOperations.cpp, 475, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    ServerVaultObjectPropertyOperationsHelper.cpp, 415, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCObjectOperationsHelper.cpp, 109, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    CoRPCOverCOM.cpp, 6153, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperations.cpp, 7384, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    MCallInLoop.h, 712, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 3930, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 3460, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelperPrivate.cpp, 10809, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 10495, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    RPCDocumentOperationsHelper.cpp, 11898, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultTrTrackerHelper.cpp, 425, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultTrTrackerHelper.cpp, 1118, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    VaultTrTrackerHelper.cpp, 1323, Operation not allowed. Script is being executed for the object "48". (0x80040834)
    (M-Files 21.4.10123.9)

  • I have just had time to test this, and can confirm that this does not seem to be directly possible, at least in a general way, using the events you mention.

    I tried to change the permissions on an object that was not checked out.  In the "BeforeSetObjectPermissions" event handler I could not call "SetProperty" as it complained that the object was not checked out, but I could not call CheckOut as it complains about the script running.

    What is interesting is that if I check the object out manually (in the desktop client: right-click and check out), then the SetProperty call on its own works fine (no checkout/checkin needed); when the object is checked in, it has the updated property value.  Unfortunately, though, this is not how users generally interact with objects, so it's not a good solution.

    My initial testing seems to indicate that the same occurs with AfterSetObjectPermissions.

    My conclusion is that this is not going to be possible to write this in a meaningful way using BeforeSetObjectPermissions/AfterSetObjectPermissions events.

    I think that you may need to do this within a "BeforeCheckInChangesFinalize" event handler (this runs for both new and updated objects).  That most definitely CAN update the object properties.

  • Hi Craig!

    Thank you for your answer! I am sure that I could use BeforeCheckInChangesFinalize eventhandler, but the problem is that changing of only permission (not properties) is not followed by adding a new version of object. I mean I can chenge permissions a few times and all of these changes will be saved in the same version of object, overriding each other. But my task is to compare the current permissions and the previous one and trigger my code only if permissions was changed in comparsion to previous permissions (even if previous permissions was set in the current verson of object).

    In BeforeSetObjectPermissions I can do this, but in BeforeCheckInChangesFinalize I can compare permissions only to that ones tha was set in previous version of object, but in this case i will miss all permissions that was set in the current version of object.

  • You are correct.  If there's no metadata/file change then BeforeCheckInChangesFinalize will not fire.

    I can think of a possible approach, but not using VBScript.

    Using the Vault Application Framework you could have a task queue.  In your BeforeSetObjectPermissions (or AfterSetObjectPermissions) you would add a task into the queue saying that this object needs to be modified.  Your code would react to this task needing to be done, check out the object, make the changes, then check it in.

    Regards,

    Craig.