How to limit the popup research

Hi,
I need to customize the accounts pop.view.php so that if role = “my role” the displayed records are searched only with particular where conditions.

I created an override in custom> modules> accounts> views


if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

global $current_user;
include_once(‘modules/ACLRoles/ACLRole.php’);

class CustomAccountsViewPopup extends ViewPopup{

    public function listViewProcess(){

        parent::listViewProcess();

        $roles = getUserRoleNames($current_user->id);
		
		If ($roles=="my role"){

..........................................
		
		}
    }

    function CustomAccountsViewPopup(){

        parent::ViewPopup();
    }

    function preDisplay(){
        parent::preDisplay();       

    }
}

but now I don’t know how to limit the query and fish only among some records.

Can anyone give me a suggestion? Is it possible?

Thanks.

I think this might help

https://suitecrm.com/suitecrm/forum/developer-help/27499-popupdefs-static-enforced-criteria/

Hi anche thanks but I am seeing that it is very difficult to get what I need.

Instead, another way could be to convert a select extracted from accounts to a dropdown list in my custom module edit view
Does this look simpler according to your experience?

I am not sure if it’s simpler that way :dry:

You would make it a Relate field, and then have to customize the way it searches, in code. Look for answers here mentioning “sqs” which is the name of the find-as-you-type search feature in dropdowns.

Well, on this way I found a solution but I don’t know how right it is:

  • I created an “enum” field integrating my custom module vardefs, requesting ‘function’ => ‘myfunction’

  • I added my php file to the custom / Extension / application / Ext / Utils where I fill the dropdownlist with my query

Now both the dropdownlist and the value saved in the database but how do I show the saved (selected) in view and edit?

I’m sorry, but I don’t understand your solution, can you post the exact code you added?

Well,
in the end I solved it.
Here is my solution that I hope will help others:

  • I created my dropdown field by Custom > Extension > Module > MyModule > Vardefs > myfield.php
  • I populated my field by Custom > Extension > application > Utils > populatemyfield.php

<?php
function getMyfiled(){
	static $myfield = null;
	if(!$myfield){
		global $db;
		
		$query = "SELECT ........... WHERE ............ORDER ..............";
		
		$result = $db->query($query, false);
 
		$myfield= array();
		$myfield[''] = '';
 
		while (($row = $db->fetchByAssoc($result)) != null) {
			$myfield[$row['name']] = $row['name'];
		}
 
	}
	return $myfield;
}

Everything is shown and saved correctly.

1 Like