Want to display an auto generated id in a custom module of SugarCRM - triggers

I am using Sugar Enterprise 6.4.0 and want to display a uneditable field in a custom module Edit and Detail view. This id need to be generated automatcially and need to be displayed in the interface when user click to create a new record in the custom module.
Because i am new to Sugar can anyone help me out in performing this task. Any ideas?

You can set the readonly property on the field itself in the vardefs for the module...
$dictionary['<<module>>']['fields']['<<fieldname>>']['readonly'] = true;
Then, add some logic in the custom/modules/<>/views/view.edit.php which does the autogeneration for you.

I just did this, using an after_save_hook with code like(not exact):
$bean->name = $bean->id;
as soon as you save a record in sugar an id is generated automatically. Then I don't include the ID in the editview at all, just the detail and list views. I don't see any point in including it in the edit view as it is not editable.

Related

Including list view of relationship entity on update page

I am trying to extend an update view to include a list view of some related items below the edit form.
I have two models, Publishers and Volumes, which have a many to many relationship. What I am trying to do is this.... when a user clicks on the edit button for a publisher, I want them to go to a page with the standard edit fields, but also have a list view below the form that lists all of the volumes that are connected to that publisher via their relationship.
Is there an easy way to do this?
I hope this makes sense.
As #tabacitu mentioned, Backpack doesn't currently have an built in solution for this. That said, this could maybe work for you:
This would allow you to use all functionality of the nested list view including interacting with the entities without conflicting at all with the parent
Step 1, Build your normal CRUDs
Build out two normal CRUDs, one for Publishers, and one for Volumes
Step 2, Make a frameless layout
copy vendor/backpack/base/layout.blade.php
name it frameless-layout.blade.php
remove #include('backpack::inc.main_header') and #include('backpack::inc.sidebar')
Step 3, Make a custom list view
copy vendor/backpack/crud/list.blade.php
name it sub-list.blade.php
change the top line to #extends('backpack::frameless-layout')
Step 4, Make a custom field
Create a custom form field that contains an iFrame
Inside your custom field template, have it set the url of the iFrame to the "list" url of the related resource
You'd also need to utilize List Filters and a method for setting them dynamically so that the sub-list shows only the records related to the parent
Step 5, Configure and use the field
In your crud controllers, use the addField to add the the configuration for the new field and its related model
Indeed, there's no standard functionality to do that in Backpack. It's a pretty unusual way to do things. But it's not too difficult to achieve it.
If there aren't too many Vendors for one Publisher (as I expect it's the case here), I would keep it simple and NOT try to include the entire Backpack list view (with ajax, buttons, filters, etc) on top of the form. I would add a standard HTML table with the entries (and optionally buttons to Edit Vendor with target=_blank).
Here's how I would go about it:
In the Publisher CRUD, I would use a custom view for the Edit operation; you can do that using $this->crud->setEditView('edit_publisher_with_vendors') in your setup() method;
In that custom edit view (edit_publisher_with_vendors.blade.php in my example), I would copy-paste everything inside the edit.blade.php view that Backpack/CRUD is using, and add a table with the Vendors on top of the Edit form; notice you have the current entry as $entry in this view; since there's a relationship on the model, you would be able to check if it has vendors using $entry->vendors()->count(), and get the vendors using $entry->vendors.
Hope it helps.

SugarCRM installable changes in detailview

I have a simple problem but may be serious for me , I made custom fields and added them all in the custom\modules\Leads\metadata\detailviewdefs.php (detailview layout) of Leads module but problem is that i have to make a installer package of changes. I managed with custom fields and copied them in the custom\Extension\modules\Leads\Ext\Vardefs through manifest. Now i don't know how to apply detailviewdefs changes through manifest (add new fields panel in detailview). The point is that the existing detailview layout should not be changed but only add a new panel in it.
Possible solution in my mind is like I should add code in $layout_defs array $layout_defs["Leads"]["DetailView"] ['panels']['panel_name'] and place it in custom\Extension\modules\Leads\Ext\Layoutdefs\ and copy Layoutdefs file through manifest. I tried this but not seems working one.
Looking for a smart solution share if you can.
Addition:
Even if i export module changes from Studio ->export Customizations and import in other instance with module builder. It override all the previous custom files(customizations) in newer instance (Is it not a limitation in SugarCRM) but my requirement is to add only changes in newer instance's detailview.
That's a tough one. There are two options that I know of. 1) Provide directions to the user for how to add the fields to the layouts using Studio 2) In a post_install.php script mimic how a Studio layout deploy works to insert your fields into any given layout (best practice would be to create a new panel for all of your fields if mass distributing).
I had found following functions of sugar's ModuleInstaller class to add or remove fields from layouts through manifest script. These functions will add/remove fields to both editview and detail view at the same time. Just add following lines in post_install / pre_install no need to require anything,
$installer_func = new ModuleInstaller();
$layoutAdditions = array('Users' => 'users_access');
To add users_access field in Users module:
$installer_func->addFieldsToLayout($layoutAdditions);
To remove users_access field from Users module:
$installer_func->removeFieldsFromLayout($layoutAdditions);
Hope it's helping.
mansoor

SugarCRM 6.2 - Adding a custom field in user profile

Yeah. As the title says, I am tasked with creating custom field in user profile, and sort of hit a wall on this one. It is a very small customisation, add a yearly_target field to user edit and detail view.
I was happy to stumble on this article to add a custom field in sugar.
Although it's a huge help, it seems to be missing one or 2 minor points.
To have the fields show in edit and detail views, one apparently needs to create and edits EditView.php and EditView.tpl and DetailView.php and DetailView.tpl, except I am not too sure where these files go. The yearly target field shows up in user list view, but not in edit/detail views. I tried custom/modules/Users , custom/modules/Users/ext , but changes made in the templates (static html changes) have no effect.
Anyone know where these files should go?
Thanks SO'ers!
They should go in the custom/modules/Users/ directory. Do make sure you change the references inside the EditView.php and DetailView.php files to reference the templates you have in the custom/modules/Users/ directory instead of the default ones in the modules/Users/ directory.

sugar CRM 6.1 .how do i edit Detailview of account module

I am working on customizing sugar CRM 6.1 . I am editing Detailview of account module,
In detailview I am adding a custom array stored in this variable
$this->bean->extra_phonenumbers = array( "phone1" =>'434343' , "phone2"=>'32323223' , "phone3"=>'344343545679');
Can anybody help me how to display these array systematically in Default viewdetail.php of Account module.
You can see view.details.php in account module <baseurl>/modules/Accounts/views/view.details.php
Declare this field in vardefs.php for Accounts and then add it to metadata/detailviewdefs.php. You can use customCode property for non-standard displays - see how it's done for existing fields there.
If you are editing Detailview "View" class then you can assign that field to a smarty variable $this->ss->assign and add in detailviewdefs to show that field with customCode as suggested above if needed.

Zend Form multiselect array

I am using the Zend Framework and have setup a normal Zend Form, what I want to try to achieve is to have a button (with some javascript) that says add more and it adds another drop down menu same as the one setup in the zend form (a clone of it).
basically when the button is clicked it adds another select box like so:
<select name="type[]"> ...</select>
I can do a copy of the multi select box with a different name and insert it in the DOM and catch the post from the controller outside of the Zend form but what I was wondering if there is a proper way to achieve this and be able to validate and populate the extra fields when editing a current data stored in db if there are any extra.. Any help is appreciated, thanks.
Well remember that in your controller if you have something like:
$this->form = new Form_Someform();
You can always do:
$this->form->addElement(etc...)
Right before using isValid() or populate.
So in your controller when someone submits the form, when creating your form object you could check if any select were created dynamicaly and then create corresponding Zend_Elements and just validate against that.
Also when you reload that form you just create elements depending on whats in your database.
You could also use the forms constructor to pass in an array of selectboxes and create then right there too. Thats what I do.
The important things to remember is that you have control on the constructor and on the form object between its creation and the use of the populate() and isValid() functions.
Hope this helps.