Closed frugardc closed 13 years ago
What are you trying to do?
For historical forecasting, once an opportunity gets cancelled, we want to create a copy of that opp with a negative revenue to cancel out the positive. Not my rules, just a requirement I have to fill. So I basically just want to clone an opp, switch the revenue to negative, and save it.
On Fri, Apr 22, 2011 at 10:53 AM, davidsulc < reply@reply.github.com>wrote:
What are you trying to do?
Reply to this email directly or view it on GitHub: https://github.com/chicks/sugarcrm/issues/47#comment_1044109
You should be able to achieve that this way
opp = SugarCRM::Opportunity.first
opp2 = SugarCRM::Opportunity.new(opp.attributes)
# manipulate opp2
opp2.save!
It is to be noted that when you call new
with an attributes array, the 'id' value is automatically stripped if it is present. Depending on your particular case, there may be other attributes you want to remove...
If you're doing this a lot, you might also want to put the code to do it in an extension.
Let me know if you run into issues.
perfect. Thanks!
On Fri, Apr 22, 2011 at 11:01 AM, davidsulc < reply@reply.github.com>wrote:
You should be able to achieve that this way
opp = SugarCRM::Opportunity.first opp2 = SugarCRM::Opportunity.new(opp.attributes)
manipulate opp2
opp2.save!
It is to be noted that when you call
new
with an attributes array, the 'id' value is automatically stripped if it is present. Depending on your particular case, there may be other attributes you want to remove...Let me know if you run into issues.
Reply to this email directly or view it on GitHub: https://github.com/chicks/sugarcrm/issues/47#comment_1044132
No problem.
Is there a module object "copy" or "clone" functionality?
Something like...
opp = SugarCRM::Opportunity.first
opp2 = opp.clone