SugarClub
SugarClub
  • User
  • Site
  • Search
  • User
SugarClub
SugarClub
  • User
  • Site
  • Search
  • User
DevClub
DevClub
Dev Tutorials Did you know? Copying related records is a breeze!
  • Dev Blog
  • Answers & Best Practices
  • Dev Tutorials
  • Developer Events
  • Developer Suggestions
  • Members
  • Tags
  • Event Recaps
  • Sub-Groups
  • More
  • Cancel
  • New
Click here to join "DevClub" to engage in the conversation with this group and curate your SugarClub experience.
  • Adding a google reCAPTCHA in a Web-to-Lead form
  • Developer Tutorials
  • Did you know? Copying related records is a breeze!
  • Getting Started with SugarCRM Development
  • How to write code for SugarCloud webinar Q&A
  • HOW TO: enforce ACL on Tags
  • On-Boarding new Sugar Developers
  • Programatically manage Dropdown List
  • Remove custom fields created via package installation
  • Sugar 10.0 (Q2 2020) Customization Guide
  • Sugar Developer Blog Style Guide
  • Sugar Developer Tools
  • Sugar Developer Webinar - Q2 2020 (10.0.0)
  • Sugar Developer Webinar - Q3 2020 (10.1.0)
  • Tutorial:  How to register custom platforms in Sugar instances via Platform extension

Did you know? Copying related records is a breeze!

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!

  • sugar 7.x
  • copy
  • copy related
  • Share
  • History
  • More
  • Cancel
Anonymous
  • Francesca Shiekh
    Francesca Shiekh over 3 years ago in reply to Hemant Patil

    Indeed. I have some modules where I added a "copy from parent" option to the subpanel top buttons to allow the user whether to copy or not.

    In other cases, we wish to copy regardless of user preferences and it's nice to know that it can be done with very limited coding.

    FrancescaS

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Hemant Patil
    Hemant Patil over 3 years ago

    Its really helpful for custom requirements, But I think it will be applied to all copied records and users may not want to copy records always.

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Related
Recommended