Customize select option on subpanel in SuiteCrm - sugarcrm

I wanted to know if there's a way to customize the select option from the subpanel men in Suitecrm.
All one-to-many relationships for a module's subpanel are to be removed whereas for many to many need to rename it to "Associate Module 1 to Module 2 ".
Can I achieve this and this is to be done for all modules.

To remove buttons:
Assume that Target module and Lead module has one to many Relationshipship. Now Leads will be shown under the Traget Record Detailview. So if we want to remove selection and creation of Lead from Subpanel of Lead. Then we can hide this two buttons from following code:
Find The relation ship file in
custom/Extension/modules/Prospects/Ext/Layoutdefs/prospects_leads_1_Prospects.php
Remove Commented code as commented in this relationship code as Below,
And then Repair and Rebuild.
$layout_defs[“Prospects”][“subpanel_setup”][‘prospects_leads_1’] = array (
‘order’ => 100,
‘module’ => ‘Leads’,
‘subpanel_name’ => ‘default’,
‘sort_order’ => ‘asc’,
‘sort_by’ => ‘id’,
‘title_key’ => ‘LBL_PROSPECTS_LEADS_1_FROM_LEADS_TITLE’,
‘get_subpanel_data’ => ‘prospects_leads_1’,
‘top_buttons’ =>
array (
/*
0 =>
array (
‘widget_class’ => ‘SubPanelTopButtonQuickCreate’,
),
1 =>
array (
‘widget_class’ => ‘SubPanelTopSelectButton’,
‘mode’ => ‘MultiSelect’,
),
*/
),
);
moreover, you can check labelvalue and then change label in language file accordingly.
To Rename button at system level:
Place following language label in custom/include/language/en_us.lang.php
$GLOBALS['app_strings']['LBL_SELECT_BUTTON_LABEL'] = 'your label';
This will change the label for all but if you want to change it via some logic then see file: include\generic\SugarWidgets\SugarWidgetSubPanelTopSelectButton.php, it has public function getDisplayName() where you can add some logic to change that label in a specific condition. Hopefully, you will write that logic your own. Also, you can return empty html in those cases where you don't need button.

Related

Magento 2 - Hide/Show custom EAV attribute after if condition

I created a new EAV attribute using this code :
'information',
[
'type' => 'int',
'default' => null,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => false
]
this attribute is by default hidden, but I want to visible it after a condition, is there any method to do that?
The visibility of the attribute is set per global or store view, so this should not be possible. However, when you display your attribute, for example on your product view page, you can build in some logic to decide wether it should be displayed or not.
Solution 1
Here's an example I used in a similar way in phtml on product view:
<?php
$product = $block->getProduct();
$attribute = $product->getResource()->getAttribute('attribute_code')->getFrontend()->getLabel($product);
if('>>your_condition_here<<'){
echo $_attribute;
}
?>
You could use this anywhere you want, especially outside of the details tab.
Solution 2
Another way would be to extend the default detail tab and build in your condition. Copy vendor/magento/module-catalog/Block/Product/View/Attributes.php to your module or theme and extend the first if condition (line 83)* in getAddtionalData() to your needs.
Change
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr))
To
if (($attribute->getIsVisibleOnFront() || ($attribute->getAttributeCode() == 'information' && '>>>your condition here <<<')) && !in_array($attribute->getAttributeCode(), $excludeAttr))
*I should add that this works for M2 2.2.x. I don't know about 2.3

Date validation for custom field - SuiteCRM Version 7.10.4 Sugar Version 6.5.25 (Build 344)

I have two fields in my module called: start_date_c & end_date_c with date datatype
These fields are not mandatory fields however when i enter data into the end_date_c field I would like to make it is not less than start_date_c
I have tried the following:
https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/12522-how-to-validate-start-and-end-date-in-suitecrm
http://sugarmods.co.uk/how-to-add-custom-validation-to-form-fields-in-sugarcrm/
but as i am new to suiteCRM, i am not able to find positive response
You will need 2 things
Edit the file editviewdefs.php in the module you want to add the logic. This field will be autogenerated when you add the first custom field to the edit view.
Create your custom JS logic to define when the field is valid.
This logic here will add a validation callback for your
addToValidateCallback(
'EditView', // Form Name
'end_date_c', // field name
'datetime', // Field type
false, // Is required
"End date cannot be earlier than start date", // Message
function() {
//WRITE YOUR JS VALIDATION HERE, return true when is valid
});
In the editviewdefs.php find the field definition and use the displayParams to make suite/sugar add the JS for you.
array (
'name' => 'end_date_c',
'displayParams' =>
array (
'updateCallback' => 'FUNCTIONNAME',
),
),
The last step ain't needed if you already have a global custom JS (like style.js file for a custom theme).
EDIT: javascript DisplaParams will not work, so added the updateCallback option.
Now this validation works in 2 ways.
The updateCallback will be fired onChange
The addtoValidateCallback will be fired on Save.
This will give you enough flexibility to validate the form.
Simple and one linear, try following in any JS file (added in module edit view):
addToValidateDateBefore('EditView', 'start_date_c', 'date', false,'Date Start', 'end_date_c' );
worked for me.I added the following code to the fields in modules/custom_module/vardefs.php
'audited' => true,
'enable_range_search' => true,
and added the following to the start field
'validation' =>
array (
'type' => 'isbefore',
'compareto' => 'enddate',
'blank' => true,
),

SugarCRM v6.5 How to get the field from another module and display it into a different module?

I know about the relationship but they only get the primary field, not the other fields. For example, I have two modules, module 1 holds the personal information of the user while module 2 let us say holds the person's activities. in module 2 I would like to display the gender base on his information from module 1.
How can I proceed with this?
Please follow below steps to achieve this:
Note: Make sure the Module-1 and Module-2 has one of the relationship 1-M or M-M
Step-1: Create new field in Module-2 to store/display the gender
values
Step-2: Create new file in Module-2
location(custom/modules/Module2/views/view.detail.php)
<?php
require_once('include/MVC/View/views/view.detail.php');
class Module2ViewDetail extends ViewDetail {
function Module2ViewDetail() {
parent::ViewDetail();
}
function display() {
$recordId = $this->bean->id;
global $db;
if($recordId){
/* write a query to fetch gender($gender) from module */
}
$this->dv->process();
$this->ss->assign('GENDER',$gender);
echo $this->dv->display();
}
}
?>
Step 3: \custom\modules\Module2\metadata\detailviewdefs.php
Add the customCode in the gender field which you have created in Module2 like below. (Please note: Give the name of field similar to you custom field name):
1 =>
array (
0 =>
array (
'name' => 'gender_c',
'label' => 'LBL_GENDER',
'customCode' => '{$GENDER}',
),
1 => '',
),
Hope this will help you. Thanks!

Perl Mechanize Click A Radio Button

I am trying to click a radio button by using Perl with Mechanize module . I tried
$mech->find_all_inputs ( name => "name" , value => "1" )
, but could not get any result. The html code of the radio button is like that;
<input name="name" value="1" type="radio">
And there are other radio buttons with the same name but different values.So how can I click the radio button using Mechanize module?
Thank you in advance.
The user agent cannot magically distinguish the right one. Find them all, and then go through them and pick the one(s) you need. You can learn values by the method possible_values
# Finding the field name and values for the radio element
foreach ( $ua->find_all_inputs(type => 'radio') ) {
$radio_name = $_->name;
say "$radio_name values: " . join('|', $_->possible_values)
}
If it's just one
my ($radio_name, $input_err) =
map $_->name, $ua->find_all_inputs(type => 'radio');
warn "More radio inputs than expected: $!" if defined($input_err);
Once you have the right button you can fill the form in which it is. For example
$ua->submit_form( fields => { $radio_name => 'AND' });
The submit_form "lets you select a form from the previously fetched page, fill in its fields, and submit it." [from docs, WWW::Mechanize]. It takes parameters as hashes, where you can set names and values, for example. This method is a higher-level wrapper, instead of which you can use more specific ones, for example
$ua->field( $name, $value );
To set a field among duplicate ones, pick the number of the one you want. For example, to set the second one from the list
$ua->set_fields( $name => [ 'field_value', 2 ] )
Also note that WWW::Mechanize inherits heavily. When you search for the right call it may be a good idea to look through methods in the packages that it inherits from.

ZF2 refresh input filter after dynamicly adding elements to form

I have a form that triggers on event in __construct method to load some items from another modules . So far so good , a field set is loaded from the other module and added to the form and in the request->getPost() I have the data for the elements inside the fieldset , but the $form->getData() doesn't have the data for the fieldset.
I am calling $form->getInputFilter() before adding this fieldsets to the form and it seems that calling the $form->getInputFilter() dosn't creates the filters for the newly added elements . so how can i create inputfilters for the dynamic events without recreating the hole filters again ?
Or should i just delay calling $form->getInputFilter() untill all of the elemnts have been added to the form ?
I also added some elements to the form later what was ignored by the input filter.
My solution is most likely not exactly the best one, but as you haven't received any other answers yet, here's what I did:
I added
use Zend\InputFilter\Factory as InputFactory;
in the class where I'm validating the form data and then used
$factory = new InputFactory();
$form->getInputFilter()->add($factory->createInput(array(
'name' => 'title_str',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
)));
#Afterdark017 that works and also i think it is possible to reset the filters.
protected function resetFilters(){
$this->filter = null;
$this->hasAddedInputFilterDefaults = false;
}
but i have not tested this yet.