SugarCRM Cookbook – SugarQuery – The Basics

Sugar Developer Blog - SugarCRM

You have found yourself in a bind, and you need to query the database directly. There is no other recourse than to write a query to get the data you need. This cookbook entry is going to give you some examples on how to use our new SugarQuery API instead of direct SQL.

1. What is SugarQuery?

SugarQuery is a SQL query builder for retrieving data directly from the database.  It is used extensively within the core of the application.  For instance, the FilterAPI uses it.

It uses a bean, the beans relationships, and visibility models to build a SQL query that can be used to retrieve data.

2. The Basics

SugarQuery has a very simple interface for building queries.

The basic methods you will need to create a query are:

  • select($fields) – accepts an array of fields you would like to select
  • from($bean) – validates the query against a SugarBean at generation
  • where()…

View original post 292 more words

Creating custom view for SugarCRM module

Sugar Developer Blog - SugarCRM

Hello everyone, i guess for most of us is another day at work :)

Today i want to share with you all, how you can create a custom view for any of your modules. You can use this view to integrate some script or anything inside sugar and it will look like it comes from there. So lets get started :)

lets imagine we have created a module semi_Metadata, and we want to add a new view and menu button called administer metadatas inside it.

If you look at the picture you will see that we have a new link in the menu called Administer metadata, and with it we don’t want to show editview,detailview or listview. We want to show our custom view. To create a link we will add this code to the Menu.php inside our semi_Metadatas module.

if(ACLController::checkAccess('semi_Metadatas', 'edit', true)) $module_menu[]=Array(
"index.php?module=semi_Metadatas&action=semi_AdministerMetadata", "Administer metadata",
"Createsemi_Metadatas");

To make this link…

View original post 279 more words

Creating custom view for SugarCRM module

Sugar Developer Blog - SugarCRM

Hello everyone, i guess for most of us is another day at work :)

Today i want to share with you all, how you can create a custom view for any of your modules. You can use this view to integrate some script or anything inside sugar and it will look like it comes from there. So lets get started :)

lets imagine we have created a module semi_Metadata, and we want to add a new view and menu button called administer metadatas inside it.

If you look at the picture you will see that we have a new link in the menu called Administer metadata, and with it we don’t want to show editview,detailview or listview. We want to show our custom view. To create a link we will add this code to the Menu.php inside our semi_Metadatas module.

if(ACLController::checkAccess('semi_Metadatas', 'edit', true)) $module_menu[]=Array(
"index.php?module=semi_Metadatas&action=semi_AdministerMetadata", "Administer metadata",
"Createsemi_Metadatas");

To make this link…

View original post 279 more words

Getting Reports To User Hierarchy in Sugar CRM as Array

Create File custom_utils.php in custom/include directory and add the following functions in to it

The getReportsToUserArray Function has two parameters
$userid is the id of user
$teamArray returns the array of private team of reporting user hierarchy



function getReportsToUserArray($userId, $teamArray = array()) {
    if (!empty($userId) && $userId != 1) {
        $reportingUser = new User();
        $reportingUser->retrieve($userId);
        if (!empty($reportingUser->reports_to_id) && $reportingUser->reports_to_id != 1) {
            $teamArray[] = User::staticGetPrivateTeamID($reportingUser->reports_to_id);
            $nextuserId = $reportingUser->reports_to_id;
            return getReportsToUserArray($nextuserId, $teamArray);
        }
        return $teamArray;
    }
}

The getUserIdByPrivateTeam Function has two parameters
$teamArray is the array of private team of reporting user which will be return by above function
This Function returns the Array of userid by private team of users

function getUserIdByPrivateTeam($teamArray = array()) {
    global $db;
    if (!empty($teamArray)) {
        $privateteamstring = implode("','", $teamArray);
        $result = $db->Query("SELECT associated_user_id  from teams WHERE id in ('$privateteamstring')");
        while ($row = $db->fetchByAssoc($result)) {
            $UserIDArray[] = $row['associated_user_id'];
        }
    }
    return $UserIDArray;
}

After Getting this array we can check the selected assigned user id in this array
if the id is available we can restrict the save action by javascript or jquery in view.edit.php of case module