Announcement

Collapse
No announcement yet.

Count Related Formula Help.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Count Related Formula Help.

    Hey guys. I'm having the hardest time counting some related records.

    So I have an entity called reservations. This reservation has many to many related fields to another entity called "reservation items". These items are player spots for our laser tag arena. So if a person were to make a reservation for 6 players then we would relate to 6 records in the reservation item entity. I need to count how many records are related to each reservation record.

    My relationship setup: https://prnt.sc/11jv2am

    My formula:

    totalReservationItems = entity\countRelated(reservationItems,);

    My issue:

    When I save I get an error 500 and of course, refuse to save the record. I check the log and see this entry:

    [2021-04-17 01:17:15] ERROR: Slim Application Error Type: TypeError Code: 0 Message: Argument 1 passed to Espo\ORM\BaseEntity::getRelationParam() must be of the type string, object given, called in /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php on line 64 File: /home/admin/public_html/cometpos.com/login/application/Espo/ORM/BaseEntity.php Line: 491 Trace: #0 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Functions/EntityGroup/CountRelatedType.php(64): Espo\ORM\BaseEntity->getRelationParam(Object(Espo\ORM\EntityCollecti on ), 'entity') #1 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Processor.php(85): Espo\Core\Formula\Functions\EntityGroup\CountRelat edType->process(Object(stdClass)) #2 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Functions/Base.php(120): Espo\Core\Formula\Processor->process(Object(Espo\Core\Formula\Argument)) #3 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Functions/SetAttributeType.php(48): Espo\Core\Formula\Functions\Base->evaluate(Object(Espo\Core\Formula\Argument)) #4 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Processor.php(85): Espo\Core\Formula\Functions\SetAttributeType->process(Object(stdClass)) #5 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Functions/BaseFunction.php(101): Espo\Core\Formula\Processor->process(Object(Espo\Core\Formula\Argument)) #6 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Functions/BundleType.php(42): Espo\Core\Formula\Functions\BaseFunction->evaluate(Object(Espo\Core\Formula\Argument)) #7 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Processor.php(88): Espo\Core\Formula\Functions\BundleType->process(Object(Espo\Core\Formula\ArgumentList)) #8 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Evaluator.php(75): Espo\Core\Formula\Processor->process(Object(Espo\Core\Formula\Argument)) #9 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Formula/Manager.php(58): Espo\Core\Formula\Evaluator->process('totalReservatio...', Object(Espo\Custom\Entities\Reservations), Object(stdClass)) #10 /home/admin/public_html/cometpos.com/login/application/Espo/Hooks/Common/Formula.php(69): Espo\Core\Formula\Manager->run('totalReservatio...', Object(Espo\Custom\Entities\Reservations), Object(stdClass)) #11 /home/admin/public_html/cometpos.com/login/application/Espo/Core/HookManager.php(111): Espo\Hooks\Common\Formula->beforeSave(Object(Espo\Custom\Entities\Reservat io ns), Array, Array) #12 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Repositories/Database.php(265): Espo\Core\HookManager->process('Reservations', 'beforeSave', Object(Espo\Custom\Entities\Reservations), Array) #13 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Repositories/Event.php(121): Espo\Core\Repositories\Database->beforeSave(Object(Espo\Custom\Entities\Reservat io ns), Array) #14 /home/admin/public_html/cometpos.com/login/application/Espo/ORM/Repository/RDBRepository.php(128): Espo\Core\Repositories\Event->beforeSave(Object(Espo\Custom\Entities\Reservat io ns), Array) #15 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Repositories/Database.php(347): Espo\ORM\Repository\RDBRepository->save(Object(Espo\Custom\Entities\Reservations), Array) #16 /home/admin/public_html/cometpos.com/login/application/Espo/Services/Record.php(691): Espo\Core\Repositories\Database->save(Object(Espo\Custom\Entities\Reservations)) #17 /home/admin/public_html/cometpos.com/login/application/Espo/Services/Record.php(1230): Espo\Services\Record->storeEntity(Object(Espo\Custom\Entities\Reserva ti ons)) #18 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Controllers/Record.php(116): Espo\Services\Record->update('607a31f7c720026...', Object(stdClass)) #19 /home/admin/public_html/cometpos.com/login/application/Espo/Core/ControllerManager.php(106): Espo\Core\Controllers\Record->actionUpdate(Array, Object(stdClass), Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) #20 /home/admin/public_html/cometpos.com/login/application/Espo/Core/Api/RouteProcessor.php(84): Espo\Core\ControllerManager->process('Reservations', 'update', Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) #21 /home/admin/public_html/cometpos.com/login/application/Espo/Core/ApplicationRunners/Api.php(184): Espo\Core\Api\RouteProcessor->process('/{controller}/{...', Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper)) #22 /home/admin/public_html/cometpos.com/login/application/Espo/Core/ApplicationRunners/Api.php(112): Espo\Core\ApplicationRunners\Api->processRequest(Array, Object(Espo\Core\Api\RequestWrapper), Object(Espo\Core\Api\ResponseWrapper), Array) #23 /home/admin/public_html/cometpos.com/login/vendor/slim/slim/Slim/Handlers/Strategies/Request... [] []

  • #2
    You forgot to put the string questions:

    totalReservationItems = entity\countRelated('reservationItems');
    CEO of Eblasoft
    EspoCRM Expert since 2014
    Full Stack Web Developer since 2008
    Creator of Numerous Successful Extensions & Projects​

    Comment


    • #3
      Thank you eymen-elkum. I feel like a idiot lol.

      Comment

      Working...
      X