Overwrite the default retrieve method in custom_module class

Hello,

I’m building a custom module in which I have a custom drop-down (fetches the Account List from the db). The module has Generate Letter functionality as I need to generate PDF out it. But when the PDF template is parsed, the variable for the custom drop-down shows the drop-down id instead of the value.

I traced it down to the data object retrieved by the retrieve method in the SugarBean class. The data object contains the ID of the custom dropdown fetched from the custom module table. Instead of this ID I need the value of the custom dropdown. How do I go about doing that?

I solution I’ve configured so far is:

  1. Extend the retrieve method from the SugarBean class in the custom_module class (i.e; in //modules/custom_module/custom_module.php)
  2. Overwrite the query executed by the default retrieve method in the custom_module class and include the dropdown value instead of ID

But the retrieve method executes a lot of functions before returning the generated data object. How do I replicate it ?

Or is this a very complex solution which I’ve designed so far and there can be another simpler approach to it?

I hope you understand the query :slight_smile:

Hello All,

With not much progress on it, I directly created a SugarBean object in the custom class and passed the record id with $_REQUEST[‘record’] to the retrieve method.

It’s getting the record id alright but not getting the table name from which to query the id. I do not want to change the default functioning of the retrieve method.

Any lead on this ??

Thanks !!

Hi Sid, Your query is bit complex to understand :cheer:

so if you give some screenshots with be specific query then we can look on this.

cheers
:cheer:

Hi Jaydeep,

I have created a custom module with a custom dropdown. But the custom dropdown if used somewhere else fetches the record ids instead of the values, so I need to modify Suite’s default retrieve method so that I get the dropdown’s values as well.

But it’s not advisable to modify the default retrieve method for obvious reasons.

Hence I extended it in the module_class but now the query doesn’t get the table name.

in your dropdown, is like this i supoose

name

while calling that dropdown in other palce there only some error is there i think. can you show me that code where you are calling that custom dropdown code.

You are calling by php or jquery ?

Hi All,

I’m posting a screenshot of class custom_module in /modules/custom_module/custom_module.php

Hope this helps in understanding the query :slight_smile:

Code in /modules/custom_module/custom_module.php:

Screenshot 1:

Screenshot 2:

$id =$this->id;
$customObject = new custom_module();
$customObject->retrieve($id);

This particular portion add in the custom_module function only.

this much is enough. no need to create. another retrieve function.
I hope this thing will work for you.

Thanks for the reply Jaydeep. But this results in query timeout.

as per the process this thing works. but for timeout , there might be some other reason. better you debug the error You will find the solution

Hi Jaydeep,

Have you implemented it anywhere ? If so could you share the code with us ?

Yah sid, i have applied it in many places,

if(! empty($_REQUEST['id'])){

    $id =  $_REQUEST['id'];
    $proposal = new p_proposal();  // this is my custom module class name
    $proposal->retrieve($id);

    $account_id  = $proposal->accounts_p_proposal_1accounts_ida;        
    $account_name = $proposal->accounts_p_proposal_1_name;
}

see this way i can get the values whatever i need.

Hi Jaydeep,

Thanks for sharing the code. Is this code locate in /modules/custom_module/custom_module.php ??

yah. my this file locate in,

module/p_proposal/p_proposal.php file.

and it is working fine.

For your case some other problem is happening chekit out. its better you can post your code then we can check.

Hi Jaydeep,

This is my code. This results in a query timeout. Please go through the comments as well.

Hi sid,

it seems your code is ok.

first time while creating time this will return null value, beceause there is no value in record.

while editing time it will work . beceause that time record id will be present . so put one condition before that whether empty or not. i think for the first time its getting empty value so only some error is producing. try to do like this and check.

if(! empty($_REQUEST['record'])){

    $id =  $_REQUEST['record'];
    $custom_module = new custom_module();  // this is my custom module class name
    $custom_module->retrieve($id);
}

try it.

No it’s not empty. Whenever you load a record there’s always a ‘record’ in the URL. Anyway thanks Jaydeep for all the time and help. I guess I will have to carve out another solution for this or will have to check if there are any code updates in this. Will get back to you once this is done or if I face another hitch :wink:

Btw which version of Suite are you customizing it in ?

ok but then also,
try this way once, i am taking ann example of Aos_Quotes, check th file… i think it may help you

require_once('modules/AOS_Quotes/AOS_Quotes_sugar.php');
class AOS_Quotes extends AOS_Quotes_sugar {
	
	function AOS_Quotes(){	
		parent::AOS_Quotes_sugar();
	}

	function save($check_notify = FALSE){
        global $sugar_config;
        
        if (empty($this->id)){
            unset($_POST['group_id']);
            unset($_POST['product_id']);
            unset($_POST['service_id']);

            if($sugar_config['dbconfig']['db_type'] == 'mssql'){
                $this->number = $this->db->getOne("SELECT MAX(CAST(number as INT))+1 FROM aos_quotes");
            } else {
                $this->number = $this->db->getOne("SELECT MAX(CAST(number as UNSIGNED))+1 FROM aos_quotes");
            }

            if($this->number < $sugar_config['aos']['quotes']['initialNumber']){
                $this->number = $sugar_config['aos']['quotes']['initialNumber'];
            }
        }

        require_once('modules/AOS_Products_Quotes/AOS_Utils.php');

        perform_save($this);
        
		parent::save($check_notify);
		
		require_once('modules/AOS_Line_Item_Groups/AOS_Line_Item_Groups.php');
		$productQuoteGroup = new AOS_Line_Item_Groups();
		$productQuoteGroup->save_groups($_POST, $this, 'group_');
	}
}

all the best :slight_smile:

2 Likes

yah sid, i am using suitecrm 7.1.1 version