Extending default copy action around flex relate field

When you use the record Copy action, there are a number of ways you can prevent certain fields copying.

https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.0/Cookbook/Customizing_Prefill_Fields… 

I have used the 'simple' method successfully around basic fields contained in a copyprefill.php file under a module

eg. 

$dictionary['Bug']['fields']['description']['duplicate_on_record_copy'] = 'no';

However, I would like to override the default behaviour on a flex relate field so the user is forced to choose the parent module and record.

For example, in Tasks module (which can relate to many modules as defined in the parent_type_display dropdown list), I disabled the parent_name field copy using the method outlined above.

$dictionary['Task']['fields']['parent_name']['duplicate_on_record_copy'] = 'no';

Behaviour changed to default to 'itself'. For example, I copy a Task which is related to an Account and is named 'Speak to CEO', this copies as being related to a Task and carried forward the copied name 'Speak to CEO'

The behaviour I would like would be a blank parent type (this might involve adding blank to the parent_type_display dropdown list ?) and also not filling out the parent name, so the user is required to fill in the parent type and related record.

Any guidance welcome.

Thanks

Neil

  • Hi Neil,

    That is kind of something in Sugar's design. If you attempt to quickly create a task, the task will recognise where you are and attach the record into the task. 

    Solution to your questions: 

    1. I would not recommend you to add a parent_type blank. Because parent_type is an helper for parent_id and parent_name. Without id and name type is meaningless and they aren't going to work properly. Consider parent_type, parent_id and parent_name is one field to be controlled. 

    As I understand you feel like you need to do this because you want to make it required. You can do this only making parent_name required. This will automatically mark parent_type parent_id and parent_name required. All you need is mark parent_name required this will do what you want to do. 

    2. To solve the problem on duplicate on record copy needs to be set against parent_id field.

    In an example to tasks parent_id field, you would need to create 

    custom/Extension/modules/Tasks/Ext/Vardefs/copyPrefill.php

    <?php

    //remove a field from copy
    $dictionary['Task']['fields']['parent_id']['duplicate_on_record_copy'] = 'no';

    Then you would need to Navigate Admin > Repairs and run Quick Repair and Rebuild. 

    Then make sure that your browser cache is also refreshed. You can logout and login that would also help browser cache to be refreshed. 

    On my testings, I was able to achive what you wanted to do by following these steps. 

    Hope this helps


    Tevfik Tümer
    Senior Developer Support Engineer

  • Hi Tevfik

    Excellent. This has indeed resolved my requirement - many thanks.

    See my comments below.

    Neil

    1 - Blank entry in DD list and the way the parent fields work together.

    Understood and I agree with your advice

    2 - Clearing the necessary information on the Copy action

    a) My original line was this. This had the effect of setting defaults on a copied Task to module 'Task' (even if copied from 'Account' for example) and the name was copied from the copied Task. I removed this line.

    $dictionary['Task']['fields']['parent_name']['duplicate_on_record_copy'] = 'no';

    b) I replaced it with your recommendation and this has the effect of setting the default module to the same as the copied task but clearing the parent name field to blank.

    This is good for the business use case as typically the need will be to copy a record relating to a particular module but against a different parent

    $dictionary['Task']['fields']['parent_id']['duplicate_on_record_copy'] = 'no';

  • Hi Tevfik,

    Just a follow up on this around 'required' behaviour.

    The above achieves the behaviour of clearing the copied related 'name'.

    However, it doesn't seem to respect the 'required' setting.

    So, for example, in Tasks module I have the parent_name field set as 'required'

    When I copy a Task, on the copied record 'Required' shows in that field but I am allowed to Save without completing this field (no red alerts appear).

    The record saves with the parent type but a blank parent_name.

    If I Edit/Save, the 'required' alerts then appear.

    Neil

  • Hi Neil,

    It looks like you found a bug   I've filed the bug for you. 

    https://portal.sugarondemand.com/#supp_Bugs/83022  

    Best Regards
    Tevfik Tümer
    Senior Developer Support Engineer