Announcement

Collapse
No announcement yet.

A message in stream about fields that I do not change

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

  • A message in stream about fields that I do not change

    Hi!
    When using the Run Service Action, I change only the "Stage" field, but for some reason such records appear in Stream
    Click image for larger version

Name:	image (2)_1952841198968.png
Views:	342
Size:	56.3 KB
ID:	31885
    Service Action:
    PHP Code:
    <?php

    namespace Espo\Custom\Services;
    use 
    \Espo\ORM\Entity;
    class 
    SetStageRelationCallandOpportunity extends \Espo\Core\Services\Base
    {
        public function 
    setStageRelationCallandOpportunityAction($workflowIdEntity $entity, array $additionalParameters null)
        {
                
    $opportunity $entity->get('parent');
                
    $stage "SettingDetails";
                if (
    $opportunity) {
                        
    $entityManager $this->getEntityManager();
                        
    $opportunity->set(array(
                        
    'stage'=> $stage));
                        
    $entityManager->saveEntity($opportunity, array('skipWorkflow' => true));
                    }
        }
    //$entityManager->saveEntity($entity, array('skipWorkflow' => true));
    }
    ?>
    Attached Files

  • #2
    Video:
    P.s: sorry for the poor quality.

    Comment


    • #3
      thy to use $opportunity = $this->getEntityManager()->getEntity($entity->get('parentType'), $entity->get('parentId'));

      instead of $opportunity = $entity->get('parent');

      Code:
      public function setStageRelationCallandOpportunityAction($workflowId, Entity $entity, array $additionalParameters = null)
      {
                  $opportunity = $this->getEntityManager()->getEntity($entity->get('parentType'), $entity->get('parentId'));
                  if ($opportunity) {
                          $opportunity->set('stage' => "SettingDetails");
                          $this->getEntityManager()->saveEntity($opportunity, array('skipWorkflow' => true));
                   }
      }

      Comment


      • mr2d2
        mr2d2 commented
        Editing a comment
        there needs array ()
        if ($opportunity) {
        $opportunity->set(array('stage'=>"SettingDetails"));
        Thank you very much!

      • tanya
        tanya commented
        Editing a comment
        could be also $opportunity->set('stage', "SettingDetails"); (forget to replace => to ,)
        Last edited by tanya; 10-20-2017, 07:33 AM.

    • #4
      It works! Thank you!
      Could you tell me why there was such a problem?

      Comment


      • tanya
        tanya commented
        Editing a comment
        if you get link field, some fields could be not loaded. If you get entity, all needed fields will be loaded (except some 'many' relationship)
    Working...
    X