Unauthorized operation. A script is being executed for the object

This error: "Unauthorized operation. A script is being executed for the object" is occurring when trying to modify m-files metadata via code, all documents that we try to modify return this error, does anyone know why this is occurring?

here is the code:

thanks