Customizing vTiger custom views with dynamic “variables”

I’ve come across a problem where you have to customize your vTiger custom views by specifying particular “variables”. For instance, list the leads assigned only to the current user.

This will require some custom programming, but it can be done!

Here is how to do it:

  1. Think of a variable name that you will use for your customization.
  2. Set up a new custom view with the variable name
  3. Change some code in /modules/CustomView/CustomView.php in either the getCVStdFilterSQL() or getCVAdvFilterSQL() to replace the variable name with the correct value

For instance, here is an example

  1. I want to create a custom view for leads called “My Leads” which only displays the leads for the user logged in
  2. I create a new custom view, and set the “Assigned To” to be “CURRENTUSER” (this is my variable name)
  3. In the getCVAdvFilterSQL() function, just before the return $advfsql statement, I insert the following:

        if (strstr($advfsql,"CURRENTUSER"))
        {
            $advfsql = str_replace ("CURRENTUSER",
                $current_user->user_name, $advfsql );
        }

This replaces all instances of the CURRENTUSER variable so that the custom view is now … customized! And dynamic! And it displays only the leads assigned to the current user logged in. (The $current_user variable is a global variable in vTiger.)

Caveats:

  1. Make sure your “variable” is a very exotic term. If you use a common word, you might end up mangling your SQL statement due to the str_replace() call.
  2. I don’t know why there are two types of Custom Views called advanced and standard which require two function calls: getCVStdFilterSQL() or getCVAdvFilterSQL()

1 Comment so far

  1. [...] dynamic “variables” - II Posted April 2, 2008 A quick follow up to my previous post Customizing vTiger custom views with dynamic “variables” . There is an easy extension to enable multiple variables to be used in the custom [...]

Leave a reply