Data field logic hook incrementation in Suite CRM

Hello,

i’m modyfying behaviour of form when “Duplicate” button is clicked. Some fields should be cleared and it’s working fine. But there are 2 “data” fields that i need to be not cleared but incremented by 1 year. So i created logic hook in custom/Modules//views/view.edit.php with this code:

require_once 'include/MVC/View/views/view.edit.php';

    class myModuleViewEdit extends ViewEdit
    {
        public function display()
        {
            $this->_processDuplicate();
            parent::display();
        }

        protected function _processDuplicate()
        {
            if ($this->ev->isDuplicate) {
                $this->bean->field1_c = '';
                $this->bean->field2_c = '';
                $this->bean->field3_c  = '';
                $this->bean->field4_c  = '';
                $this->bean->datafield1_c = (what code should i use here?)
                $this->bean->datafield2_c = (what code should i use here?)
            }
        }
    }

I tried to use DateTime function but there was 2 problems --> date has been incremented but starting from today (not from date which was in duplicated record field) and there was time in new field which shouldn’t be there.

And my second question linked with Duplicate button is: can I somehow add duplicate button to subpanel which appears in row position (not at the top of subpanel)? I can add 2 fields via Studio: Remove and Edit but there is no option to choose Duplicate button from there.

Can you guide me through this little i think problems please?

Btw, sorry for my english but i’m still learning it hard :frowning:

for the year thing try this

$this->bean->datafield1_c = date($this->bean->datafield1_c, strtotime('+1 years'));

for the second one take a look at this post, maybe it can help you https://suitecrm.com/forum/developer-help/10549-add-a-custom-action-to-the-buttons-on-the-right-of-a-subpanel-row#36200

best regards

1 Like

Hi Mike - thank you for your help,

however, first code doesn’t work. Nothing happens with datafield if i use it - still stays with date from duplicated record.

I need to try out your second tip with row button implement in the evening - and i will give you a feedback if it’s working.

I have one little question - i’ve moved my suite from 6.5 version to 7.6 and there seems to be a problem with editing existing fields. Everytime i want to edit/save/modify my custom fields in studio i get a message: “Field name already exist” and i can’t change anything. Only creating new field is working. But i have 18k records in base and it’s not good idea for me to create all the fields again. So: Is there any option to modify/add/remove checklist items via editing some file in suitecrm root directory? I’ve searched everywhere i think, and if i would like to change name of the field etc - there is no problem, but i can’t see file where my checklists items are stored…

Thank you for your patience my friend.

take a look at this example for the +1 year thing that you need http://stackoverflow.com/questions/18269556/php-date-add-1-year-to-current-date then try to manipulate your variable as I tried without testing it :wink:

There’s no suite 6.5, you mean SugarCRM 6.5? SuiteCRM started on version 7, or maybe you mean 7.6.5? anyway… You problem is maybe fixable with a repair and rebuild if you haven’t touched anything non upgrade safe, because if you did I don’t think is fixable. Try to read your webserver’s and suitecrm’s logs.

best regards

1 Like

Nice! You are GREAT! A code for working date field incrementation by 1 year is:


$this->bean->datafield1_c = date('Y-m-d',strtotime(date($this->bean->datafield1_c, mktime()) . " + 365 days"));

And of course i meant SuiteCrm 7.5 :wink: Unfortunately nothing helps and editing existing fields via studio is not possible :frowning: I hope i will find some way to edit checklists “from backstage” :wink:

Now i’m trying to achieve row duplicate button with tips you gave me and but it’s not that simple as it looks. I will give you a feedback when i’m done. If you will figure it out first then don’t hesitate to give me some advice :wink:

Best regards

Little modification to my previous code, cause it was not working properly (+365 days --> 1 year):

$this->bean->datafield1_c = date('Y-m-d',strtotime(date($this->bean->datafield1_c, mktime()) . " + 1 year"));

Is there any option to set fixed width in module’s listview? For example in Accounts module, when account name is long then it’s moving whole table to the right so other fields in list view are very “compressed”… Setting f.ex 5% width in studio for a fields isn’t change anything.

Thank you in advance.