Announcement

Collapse
No announcement yet.

Workflow to update a field if an other field has changed

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

  • Workflow to update a field if an other field has changed

    Hi All,

    I would like to setup a simple workflow which would update a field if an other field is changed, with the new value.
    We have an advanced pack version 2.3.10 and Espo version 5.6.14.
    This is what I have tried so far:

    1,
    ifThenElse(mailerLiteCountry!=null, addressCountry=mailerLiteCountry);
    ifThenElse(addressCountry!=null, mailerLiteCountry=addressCountry);

    2,
    ifThen(record\exists('Lead', 'addressCountry='), mailerLiteCountry=addressCountry);
    ifThen(record\exists('Lead', 'mailerLiteCountry='), addressCountry=mailerLiteCountry);

    Log: Espo.ERROR: Workflow[5d9b46ea0f0f94949]: Action failed [updateEntity] with cid [0], details: . [] []

    3,
    ifThen(entity\Attribute('mailerLiteCountry'), addressCountry = mailerLiteCountry)

    I am not sure why it is not working, any help would be appreciated.

    Regards,
    Balazs

  • #2
    Hello Blaz,
    I believe that you can make this automation utilizing Formula w/o Workflow. It is not mandatory to use Formula in Workflow.
    Here are a few reasons why your Formula is not working.
    1. The 'ifThenElse' construction esumes that you need to use 3 parameters: condition, consequent, alternative. You gave only two.
    https://github.com/espocrm/documenta....md#ifthenelse.

    2. record\exists construction esumes that you need to use at least 3 parameters. You gave only two.
    https://github.com/espocrm/documenta...d#recordexists.
    Code:
    > Log: Espo.ERROR: Workflow[5d9b46ea0f0f94949]: Action failed [updateEntity] with cid [0], details: . [] []
    I don't know why action was failed. Perhaps a screenshot of its configs can tell more.

    3. There is no such Formula construction as 'entity\Attribute'.

    Comment


    • #3
      Hi,

      Thank You for the answer, now I am getting somewhere.
      I basically just want to mirror these 2 fields, when a lead is created and when one of the fields are modified.
      I have this code now under Lead Formula:

      ifThen(
      entity\isAttributeChanged('mailerLiteCountry'),
      addressCountry = mailerLiteCountry
      );
      ifThen(
      entity\isAttributeChanged('addressCountry'),
      mailerLiteCountry = addressCountry
      );
      ifThen(
      entity\isNew() && mailerLiteCountry != null,
      addressCountry = mailerLiteCountry
      );
      ifThen(
      entity\isNew() && addressCountry != null,
      mailerLiteCountry = addressCountry
      );



      When I modify a lead and change either mailerLiteCountry or addressCountry, the changes are going through to the other field ok (back and forth).
      When I create a Lead, and fill in mailerLiteCountry, the addressCountry field is updated ok.
      But when I create a Lead and write in addressCountry field, the field is not saved, and changes are not done on mailerLiteCountry field either.
      Please note mailerLiteCountry field is text type and addressCountry field is varchar by default. I am not sure if it is a problem? (I have tried to change addressCountry to text but still it was not working)

      So I guess this part of the formula should be fixed somehow:

      ifThen(
      entity\isNew() && addressCountry != null,
      mailerLiteCountry = addressCountry
      );


      Log level is on debug now, but there are no errors or warning in the log.

      Any help would be appreciated.

      Regards,
      Balazs

      Comment


      • #4
        I have tested your formula and it's ok. This issue was caused by web browser cache. Try to test it in the incognito window mode. It should works.

        Comment


        • #5
          Hi,

          Thank You for testing.
          Are You sure it is a cache issue? When creating a new Lead and filling the addressCountry field the data not gets into mailerLiteCountry field for me and addressCountry field stays null/none.
          I have tried incognito window, and 2 different browsers (Firefox and Opera) by default I am using Chrome.
          We also have 2 installations of EspoCRM, one is a test system and one is live. Same thing happens on the live install as well.
          By the way it is very interesting that if an API user creates a Lead or a normal user through Espo's API it seems working.
          It is only the User interface which does not work.
          In devtools console I also can not see anything.
          Do You have any idea?

          Regards,
          Balazs

          Comment


          • #6
            Hi,

            Not sure why but it is working now thank You very much.

            Regards,
            Balazs

            Comment

            Working...
            X