warning undefined key "calculated"

Hi,

I have created a custom scheduler, which runs fine, but it gives me the following warning:

Warning [2]: Undefined array key "calculated" over /var/www/html/include/Expressions/DependencyManager.php op regel 188

I feel like this is a bug, but maybe anyone here has an explanation?

The scheduler runs the following code:

$bean = BeanFactory::retrieveBean('Quotes', "ed55fc4e-b3cc-11ef-94ac-0242ac120007");
$bean->quote_stage = 'Concept offerte';
$bean->projectcode_c = '123746';
$bean->save();

Performing a postman request to the REST API setting the same values does not result in any warnings. Any idea why this warning occurs?

Looking in the source code of Sugar I get to this line of code:

if (!empty($def['required']) && isset($def['required_formula']) && !$def['calculated']) {

...

}

I would expect either the sugar code has to be changed to:

&& (!array_key_exists('calculated', $def) || !$def['calculated'])

OR we have to figure out why $def['calculated'] is not being set.

I am running version 13.0.3

Update: running the same code on another module, does not give the same error, so it is related to the quote module. Maybe it has something to do with calculations of totals of quote line items or something?

Kind regards,

Stijn

Parents Reply
  • <?php
    namespace Sugarcrm\Sugarcrm\custom\inc\processors;

    use BeanFactory;
    use SugarBean;
    use SugarQuery;

    class MyScheduler
    {
    const RECORD_LIMIT = 100;

    public function match()
    {
    $sugarQuery = new SugarQuery();
    $sugarQuery->from(BeanFactory::newBean('Quotes'));
    $sugarQuery->select(array('id', 'quote_num'));
    $sugarQuery->where()->equals('quote_stage', 'Wacht op verwerking');
    $sugarQuery->limit(self::RECORD_LIMIT);

    $quotes = $sugarQuery->execute();
    if(safeCount($quotes) > 0) {
    foreach($quotes as $entry) {
    $entry = BeanFactory::retrieveBean('Quotes', $entry["id"]);
    $entry->quote_stage = 'Concept offerte';
    $entry->projectcode_c = '123746';
    $entry->save();
    }
    }
    }
    }
Children
  • Normally project code would be determined based on other data, but without this logic, the code still gives the same error. So to simplify I removed as much code which still results in the same error.

  • Hi  , 

    I implemented a very similar Scheduler using the standard approach outlined in our documentation,

    Here is the code I added to my instance:



    <?php
    
    //file custom/Extension/modules/Schedulers/Ext/ScheduledTasks/update_quotes.php
    
    // Register the custom job
    array_push($job_strings, 'custom_job');
    
    // Define a constant outside the function
    define('RECORD_LIMIT', 100);
    
    function custom_job()
    {
        $sugarQuery = new SugarQuery();
        $sugarQuery->from(BeanFactory::newBean('Quotes'));
        $sugarQuery->select(array('id', 'quote_num'));
        $sugarQuery->where()->equals('quote_stage', 'Draft');
        $sugarQuery->limit(RECORD_LIMIT);
    
        $quotes = $sugarQuery->execute();
        if (!empty($quotes)) {
            foreach ($quotes as $entry) {
                $quote = BeanFactory::retrieveBean('Quotes', $entry["id"]);
                if ($quote) {
                    $quote->quote_stage = 'Delivered';
                    $quote->projectcode_c = '123746';
                    $quote->save();
                }
            }
        }
    
        return true;
    }

    The job is running as expected, and I’m not seeing any warnings on my end. 

    Would you mind testing my approach to see if it makes any difference?

    Another thing I noticed is that match() is a reserved keyword in PHP 8 due to the introduction of the match expression. Could you try changing the function name to see if the behavior changes?

    If that doesn’t resolve the issue, could you share the field vardefs for both:

    projectcode_c

    quote_stage

    This would help us identify if there’s anything in the fields we are trying to edit causing the discrepancy in behavior.


    I hope this brings us closer to a resolution!


    Cheers,

    André

  • Thank you André, I am trying the suggestions, but think I will have to pin point the cause of the problem further, because the cause of the problem is still not clear. I will update this thread once I have more info.