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
  • Developer On-boarding
  • Dev Tutorials
  • Developer Events
  • Event Recaps
  • Members
  • Developer Suggestions
  • Sub-Groups
  • More
  • Cancel
  • New
Click here to join "DevClub" to engage in the conversation with this group and curate your SugarClub experience.
  • +On-Boarding Framework
  • +Customization Guides
  • +UI Redesign Technical Guide
  • Did you know? Copying related records is a breeze!
  • How to write code for SugarCloud webinar Q&A
  • HOW TO: enforce ACL on Tags
  • Programatically manage Dropdown List
  • Remove custom fields created via package installation
  • Sugar Developer Tools
  • Tutorial:  How to register custom platforms in Sugar instances via Platform extension
  • Adding a google reCAPTCHA in a Web-to-Lead form
  • Sugar Developer Blog Style Guide

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
Parents
  • Hemant Patil
    Hemant Patil over 6 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 Actions
    • Cancel
  • Francesca Shiekh
    Francesca Shiekh over 6 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 Actions
    • Cancel
Comment
  • Francesca Shiekh
    Francesca Shiekh over 6 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 Actions
    • Cancel
Children
No Data
Related
Recommended