How to return the exact same view result via COM API?

I need some clarification on how view filters work. Basically, I want to understand why the views in M-Files Desktop return a different document setup than when I query them via the COM API using the view's search conditions.

For example, this view:

This returns 11 items in the M-Files Desktop.

But when I query the view ID via the COM API, I get several thousand documents because the search condition is just this:

'Class' = 'Manual (MAN)' AND 'Workflow' = 'Document Processing'

Basically, all documents matching MAN and "Document Processing" are returned.

So, there must be something else I'm not aware of that limits the number of documents shown in the M-Files Desktop client.

It would be good to know what that is so I can address it programmatically.

Many thanks!

Parents
  • Are you using the same user account when searching via the client and connecting via the API? The search only returns those documents that the user has a permission to see, unless they are an admin user who can see all the vault content. If you are using the same user account, then you should get the same results.

  • Yes, I’m using the same account to connect to the vault via the COM API in client mode as well as for the M-Files client. I’m also not an administrator.

    Below is the source code to connect to the vault:

        def connect_client_mode(self):
            self.clear_com_cache()
            try:
                logger.debug("Creating instance of MFilesClientApplication...")
                client = win32com.client.gencache.EnsureDispatch("MFilesAPI.MFilesClientApplication")
                logger.info("Created instance of MFilesClientApplication.")
    
                logger.debug(f"Connecting to vault '{self.vault_name}'...")
                parent_window = 0
                can_log_in = True
                return_null_if_cancelled = True
    
                self.vault = client.BindToVault(self.vault_name, parent_window, can_log_in, return_null_if_cancelled)
                if self.vault:
                    logger.info(f"Connected to the vault '{self.vault_name}' successfully.")
                    return True
                else:
                    logger.error(f"Failed to connect to the vault '{self.vault_name}'.")
                    return False
            except Exception as e:
                logger.exception("An error occurred while connecting to the M-Files vault.")
                return False

    And this is the code to query the views:

                # Fetch and log the view details once
                view = self.vault.ViewOperations.GetView(view_id)
                logger.info(f"Processing view: {view.Name} (ID: {view_id})")
    
                # Retrieve and display search conditions
                search_conditions = view.SearchConditions
                self.display_search_conditions(search_conditions)
    
                # Fetch search results in batch
                search_results = self.vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(
                    search_conditions,
                    win32com.client.constants.MFSearchFlagNone,
                    False,
                    0,
                    0
                )

Reply
  • Yes, I’m using the same account to connect to the vault via the COM API in client mode as well as for the M-Files client. I’m also not an administrator.

    Below is the source code to connect to the vault:

        def connect_client_mode(self):
            self.clear_com_cache()
            try:
                logger.debug("Creating instance of MFilesClientApplication...")
                client = win32com.client.gencache.EnsureDispatch("MFilesAPI.MFilesClientApplication")
                logger.info("Created instance of MFilesClientApplication.")
    
                logger.debug(f"Connecting to vault '{self.vault_name}'...")
                parent_window = 0
                can_log_in = True
                return_null_if_cancelled = True
    
                self.vault = client.BindToVault(self.vault_name, parent_window, can_log_in, return_null_if_cancelled)
                if self.vault:
                    logger.info(f"Connected to the vault '{self.vault_name}' successfully.")
                    return True
                else:
                    logger.error(f"Failed to connect to the vault '{self.vault_name}'.")
                    return False
            except Exception as e:
                logger.exception("An error occurred while connecting to the M-Files vault.")
                return False

    And this is the code to query the views:

                # Fetch and log the view details once
                view = self.vault.ViewOperations.GetView(view_id)
                logger.info(f"Processing view: {view.Name} (ID: {view_id})")
    
                # Retrieve and display search conditions
                search_conditions = view.SearchConditions
                self.display_search_conditions(search_conditions)
    
                # Fetch search results in batch
                search_results = self.vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(
                    search_conditions,
                    win32com.client.constants.MFSearchFlagNone,
                    False,
                    0,
                    0
                )

Children
No Data