Announcement

Collapse
No announcement yet.

Trouble using entity\sumRelated function

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

  • Trouble using entity\sumRelated function

    I have created a Workflow (I will probably use a Formula in the Entity Save Before Custom Script as well) that take a purchase date, and adds an amount of weeks specified to come up with an end date that calculates on save. This works great.

    I am trying to add an additional part that sums a integer field opportunityLength in all the opportunities where it is specified and adds them as weeks to a date field. It seemed the entity\sumRelated was the perfect function for this, but I cannot seem to get a number out of it no matter what I do.

    This is my function:
    $opportunitylengths = entity\sumRelated('opportunities', 'opportunityLength');
    $totallength = lengthInWeeks + $opportunitylengths; <--- I use lengthInWeeks to add time to the total time beyond what's specified in Opportunites, this is mainly for comping extra time.
    campaignEndDate = datetime\addWeeks(purchaseDate, $totallength);

    calculatedField = entity\sumRelated('opportunities', 'opportunityLength'); <--- I use this for debugging and I consistently get None in the specified varchar field.

    Yesterday I was getting the following error: Espo.ERROR: Formula failed: Class \Espo\Core\Formula\Functions\EntityGroup\SumRelate dType was not found. [] []
    I looked and the PHP class was where it was supposed to be but today the errors seemingly just went away, not sure what was going on there.

    opportunityLength, and lengthInWeeks are int fields
    campaignEndDate, and purchaseDate are Date fields
    Espo version 5.3.6

    I am not sure what I am doing wrong.

    Thank you in advance for any help -J

  • #2
    Anyone have any experience with this function??

    Comment

    Working...
    X