Did you know? Copying related records is a breeze!

Document created by Francesca Shiekh on Mar 8, 2017Last modified by Francesca Shiekh on Jun 27, 2017
Version 3Show Document
  • View in full screen mode

I stumbled on this today and thought I'd share.

Ever wanted to copy related records when using the Copy action from Record View?

It's simple just add a vardef extension!

 

For example, I have a custom oppp_OpportunityProducts module on Opportunities.

When copying an Opportunity I also want to copy the OpportunityProducts

in 

custom/Extension/modules/Opportunities/Ext/Vardefs/<a_filename_you_like>.php

I added the following:

 

$dictionary['Opportunity']['after_create'] = array(
  'copy_rel_from' => array (
   'oppp_opportunity_products_opportunities',
  ),
);

where 

'oppp_opportunity_products_opportunities' is the link from Opportunities to oppp_OpportunityProducts.

 

Want to copy more related records? Simply add more link names to the array.

Now when the Opp is copied, the products are copied with it.

 

So simple!

Francesca

 

 

(Tested in SugarCRM 7.8 Professional)

 

NB: beware of cardinality! If your relationship is 1:M (e.g. each product can only be related to one opportunity only) the product will MOVE to the new Opportunity record and will disappear from the original!

2 people found this helpful

Attachments

    Outcomes