How to parse "$this->bean->id" into detail view metadata?

In view.detail.php of Accounts module I am able to retrieve current displaying account id via $this->bean->id but I am inserting the input field through detail view metadata file(detailviewdefs.php) in following way but it is not showing the id of current account record.


   7=> array (
                                  0 => array(
                                      'name' => 'test',
                                      'label' => '',
                                      'customCode' => '<input  type="text" value="<?php echo $this->bean->id;?>">' ,
                                  )
                                ),

Can anyone please tell me how to get bean value on metdata?

You could create the field in the way you are doing but without filling the value plus giving it a unique id.
Additionally you may create a custom logic hook that outputs some javascript that fills the field with the bean’s id value.

I have never done it but it shouldn’t be difficult.

Alternatively you may search the forum: I am not sure but I remember (I may be wrong though) that someone managed to show id’s by enabling the usage of id fields. I think that there is a configuration variable to allow the usage od that field. But I repeat, I may be wrong.

Hi, Thanks for your reply.
May I know what logic hook can be triggered before displaying detail view of a record?

can we use process_record logic hook for this?

I am not sure, but I would use after_ui_frame
In order to get the bean info you should make use:

global $bean;

Useful references:
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Logic_Hooks/Application_Hooks/after_ui_frame/index.html

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Logic_Hooks/

https://github.com/audoxcl/SugarCRMLogicHooks

You need to add the value from the view.detail.php through Smarty to pull the value into your viewdefs. Like so below:

view.detail.php


$mycustomvalue = $this->bean->id;

$this->ss->assign("MyCustomValue", $mycustomvalue);

detailviewdefs.php

'customCode' => '<input  type="text" value="{$MyCustomValue}">',

Or you could have the button already made in your view.detail.php like so:

view.detail.php


$mycustomvalue =  "<input  type='text' value='$this->bean->id'>";

$this->ss->assign("MyCustomValue", $mycustomvalue);

detailviewdefs.php

'customCode' => '{$MyCustomValue}',
2 Likes

Thank you for your reply.

You are right but How can I include below code to detail view on the installation of the module.

$mycustomvalue = $this->bean->id;

$this->ss->assign(“MyCustomValue”, $mycustomvalue);

&

what is this $this->ss means?

What do you mean “to detail view on the installation of the module.”?

Updated:

You would place the code inside your display function on view.detail.php (if you want it on the detail view).

Example for Contacts


require_once('modules/Contacts/views/view.detail.php');

class CustomContactsViewDetail extends ContactsViewDetail{
    public function display(){
        global $sugar_config, $mod_strings;

        $mycustomvalue = $this->bean->id;

        $this->ss->assign("MyCustomValue", $mycustomvalue);

        parent::display();
    }
}

The code provided will display the ID (passed in by view.detail.php) on the field where you have set in the viewdefs on.

$this->ss is the Sugar Smarty object. This object is basically how you can manipulate the smarty template setting a new tempate, assigning values to the template etc.

Let me explain this more detail.

As you showed I can write that code and copy detail.view.php file to views folder but My problem is If I do like that, suppose if there is already existing customized detai.view.php it will overridden by my file. I need this not to be happen.

So what i would like to have is when the module is installing it should add the detail view changes to existing detail view file .

If the file already exists in the custom folder, you have to edit the existing file and not just overwrite it.

The problem arises under other circumstances:
. if you are adding the customisation via module loader, when installing a custom module or package: in this case you can’t just copy the file but you have to find a way to add your code to the existing file.

Otherwise, if you are uncomfortable, try with a logic hook.

Here you find an example achieving something different, but it should be enough to find out how to do what you are trying to achieve.
http://www.jsmackin.co.uk/suitecrm/suitecrm-list-view-conditional-formatting/

You have to think on what type of logic hook you want to use and how to implement your solution.

Another alternative could be that you create a custom id field and then a workflow which copies the value of id to your custom id field. You can run this only once since the id will not change. An advantage of this solution is that it requires no coding.
A disadvantage is that the id will not be filled until the workflow has run.

Similarly you could achieve the same with a before_save logic hook when saving the record.

‘customCode’ => ‘<input type=“text” value="{$fields.id.value}’ ,