AnsweredAssumed Answered

How to duplicate a bean object

Question asked by Todd Li on Feb 24, 2016
Latest reply on Mar 15, 2016 by Todd Li

Hi everyone,

 

 

I want to duplicate a bean object.

What I did is:

$objBean = BeanFactory::getBean('Opportunities', $args['id']);

 

$objBean->id = create_guid();   or   $objBean->id = new_uuid();

$objBean->new_with_id = true;

$objBean->type = 'A'; (Different from original record)

$objBean->save();

 

I got errors like:

Wed Feb 24 10:21:11 2016 [4870][1][FATAL] Exception evaluating expression in SetValueAction, abs(subtract(daysUntil($date_entered),daysUntil($proposal_sent_c))) : value '' must be numeric

#0 /var/www/adshel/include/SugarMath/SugarMath.php(127): SugarMath->testValue(false)

#1 /var/www/adshel/include/SugarMath/SugarMath.php(67): SugarMath->setValue(false)

#2 /var/www/adshel/include/SugarMath/SugarMath.php(93): SugarMath->__construct(false, 6)

#3 /var/www/adshel/include/Expressions/Expression/Numeric/SubtractExpression.php(31): SugarMath::init(false, 6)

#4 /var/www/adshel/include/Expressions/Expression/Numeric/AbsoluteValueExpression.php(25): SubtractExpression->evaluate()

#5 /var/www/adshel/include/Expressions/Actions/SetValueAction.php(78): AbsoluteValueExpression->evaluate()

#6 /var/www/adshel/include/Expressions/Dependency.php(178): SetValueAction->fire(Object(Opportunity))

#7 /var/www/adshel/include/Expressions/Dependency.php(154): Dependency->fireActions(Object(Opportunity))

#8 /var/www/adshel/data/SugarBean.php(1880): Dependency->fire(Object(Opportunity))

#9 /var/www/adshel/modules/Opportunities/SaveOverload.php(35): SugarBean->updateCalculatedFields()

#10 /var/www/adshel/modules/Opportunities/Opportunity.php(418): perform_save(Object(Opportunity))

#11 /var/www/adshel/custom/squiz/logichooks/modules/PRODU_Product_line_items/ProductLogicHook.php(133): Opportunity->save()

#12 [internal function]: ProductLogicHook->updateQuoteProductText(Object(PRODU_Product_line_items), 'after_save', Array)

#13 /var/www/adshel/include/utils/LogicHook.php(229): call_user_func_array(Array, Array)

#14 /var/www/adshel/include/utils/LogicHook.php(159): LogicHook->process_hooks(Array, 'after_save', Array)

#15 /var/www/adshel/data/SugarBean.php(6323): LogicHook->call_custom_logic('PRODU_Product_l...', 'after_save', Array)

#16 /var/www/adshel/data/SugarBean.php(1863): SugarBean->call_custom_logic('after_save', Array)

#17 /var/www/adshel/custom/squiz/logichooks/modules/Opportunities/BeforeSaveOpportunities.php(34): SugarBean->save()

#18 [internal function]: BeforeSaveOpportunities->regenerateRevenueRecognition(Object(Opportunity), 'before_save', Array)

#19 /var/www/adshel/include/utils/LogicHook.php(229): call_user_func_array(Array, Array)

#20 /var/www/adshel/include/utils/LogicHook.php(159): LogicHook->process_hooks(Array, 'before_save', Array)

#21 /var/www/adshel/data/SugarBean.php(6323): LogicHook->call_custom_logic('Opportunities', 'before_save', Array)

#22 /var/www/adshel/data/SugarBean.php(1783): SugarBean->call_custom_logic('before_save', Array)

#23 /var/www/adshel/modules/Opportunities/Opportunity.php(420): SugarBean->save(false)

#24 /var/www/adshel/custom/modules/Opportunities/clients/base/api/Custom_OpportunitiesApi.php(77): Opportunity->save()

#25 /var/www/adshel/include/api/RestService.php(256): Custom_OpportunitiesApi->createForcastProductsQuotation(Object(RestService), Array)

#26 /var/www/adshel/api/rest.php(24): RestService->execute()

#27 {main}

 

I don;t know what I did wrong. Or what I can do to duplicate a bean object.

 

I am on Sugar7.6.0.

Thanks

Outcomes