A message in stream about fields that I do not change

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mr2d2
    Senior Member
    • Apr 2017
    • 126

    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:	347
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($workflowId, Entity $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
  • mr2d2
    Senior Member
    • Apr 2017
    • 126

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

    Comment

    • tanya
      Senior Member
      • Jun 2014
      • 4308

      #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.
    • mr2d2
      Senior Member
      • Apr 2017
      • 126

      #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...