Announcement

Collapse
No announcement yet.

Workflow - access targetRecord attribute when updating relatedRecord attribute

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

  • Workflow - access targetRecord attribute when updating relatedRecord attribute

    Hello guys,

    I am currently facing issues with one of my workflow, where I am targeting opportunities, but I would like to update the related record "Assigned User".

    Everything seems to be working fine except that I am trying to assign the value from targetRecord attribute(oportunity.amountConverted) to relatedRecord attribute(assignedUser.obrat).

    Syntax entity\attribute('amountConverted') seems to be taking value from the entity I am trying to update, not from the entity I am targeting with the workflow.

    Is there any other syntax how to access targetEntity attribute when updating relatedEntity attribute?

    Hopefully, it is clear what I am trying to achieve (screen1, screen2)

    ​Thanks a lot for the help!
    Attached Files

  • #2
    Hi Jakub Grufik,

    Please use this formula:

    workflow\targetEntity\attribute('amountConverted') ;

    Comment


    • #3
      Hey lazovic!

      Holy sht(sorry for that) it is actually working exactly as I wanted!

      Man thanks a lot, you saved my ass again and definitely not for the last time.

      Is there by any chance documentation for those syntaxes? I was not able to find this one in espoDocs.

      Thanks a lot again buddy! I owe you

      Comment


    • #4
      Hello lazovic I have a quick question, please.

      It is connected with the workflow we were discussing above.

      When I am updating relatedRecord - Assigned User in my workflow and filling it with value from targetRecord I am using special syntax you sent me "workflow\targetEntity\attribute('amountConverted') "

      Now, in the same workflow, I would like to check IF "state" in relatedEntity contact equals something. Is this the correct format please? (screen1)

      Please keep in mind that this is exactly the same workflow where I am updating relatedRecord assigned user, but I am targeting opportunity where is another relatedEntity contact and I want to get contact.addressState while updating assigned user Hope it makes sense.

      Thanks a lot
      Attached Files

      Comment


      • lazovic
        lazovic commented
        Editing a comment
        In fact, it is difficult to focus on small pieces of Workflow/BPM, in order to understand the situation, I need to see the whole picture.
        But in this situation, the syntax is correct and it looks like everything will work correctly. If you have any problems with this Workflow, I will be happy to help you.

    • #5
      lazovic oh yea I completely understand that it is basically guessing from your side if you do not have enough information.

      Please check the attached screenshots and I would be more than happy to provide you with more information if needed.

      Some quick info:
      Workflow targets entity "opportunity"
      Screen1 = settings of the workflow
      Screen2 = settings of the workflow
      Screen3 = formula of action you helped me with
      Screen4 = formula of action I want to use to update the assigned user´s attribute IF opportunity.contact.addressState = one of listed values

      Hope its more clear now.
      Thanks a lot, man!
      Attached Files

      Comment


      • lazovic
        lazovic commented
        Editing a comment
        In the last action of this Workflow, before the existing lines, add these lines:

        $contactId = workflow\targetEntity\attribute('contactId');
        $contactAddressState = record\attribute('Contact', $contactId, 'addressState');

        And then in the existing formulas, replace contact.addressState with $contactAddressState.

    • #6
      lazovic oh yeah thanks a lot man! this actually makes sense.

      Please correct me if I am wrong - the syntax I used before with "contact.adressState" was trying to take value from relatedRecord contact, which according to the used syntax should be related to assignedUser not to the opportunity, right? Hence there would be empty value, cause assigned user does not have related entity "contact", correct?
      Attached Files

      Comment


      • lazovic
        lazovic commented
        Editing a comment
        Yes, exactly, you understood everything correctly.

      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        Thanks a lot, my friend! As always, very very helpful information.

        I appreciate your valuable time.

    • #7
      lazovic oh, sorry I forgot to ask you one more question - the last one for the next hour I promise

      Is there by any chance a list or documentation with possible values that can be used in the formula to target specific ENTITY_TYPE and its ATTRIBUTE? I would love to have it to be able to use the full potential of formulas.

      Basically possible values for "ENTITY_TYPE, and possible values for its ATTRIBUTE (screen1)

      That would be all for today I guess

      Thanks a lot one more time and sorry for spamming!
      Attached Files

      Comment


      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        just for you to know, here "$contactId = workflow\targetEntity\attribute('contactId');" I am using attribute 'contactId', but I was not able to find this attribute in Administration > Entity Manager -> Opportunity -> Fields, is ID something special that is not being displayed anywhere?

      • lazovic
        lazovic commented
        Editing a comment
        This part of the documentation describes this feature:
        https://docs.espocrm.com/administrat...ing/#attribute.

      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        will check, thanks a lot. That would be all from my side for today, have a nice rest of the day buddy

    • #8
      Originally posted by Jakub Grufik View Post
      Hello guys,

      I am currently facing issues with one of my workflow, where I am targeting opportunities, but I would like to update the related record "Assigned User".

      Everything seems to be working fine except that I am trying to assign the value from targetRecord attribute(oportunity.amountConverted) to relatedRecord attribute(assignedUser.obrat).

      Syntax entity\attribute('amountConverted') seems to be taking value from the entity I am trying to update, not from the entity I am targeting with the workflow.

      Is there any other syntax how to access targetEntity attribute when updating relatedEntity attribute?

      Hopefully, it is clear what I am trying to achieve (screen1, screen2)

      ​Thanks a lot for the help!
      you can simply use targetEntity\attribute('amountConverted')​ check out the documentation here https://docs.espocrm.com/administrat...#formula-usage this works for both bpmn and workflows.
      Rabii
      Web Dev

      Comment


      • #9
        hello rabii thanks a lot for the help.

        Could you please tell me if there is any difference between targetEntity\attribute('amountConverted')​​ and workflow\targetEntity\attribute('amountConverted') ?

        I am currently using workflow\targetEntity\attribute('amountConverted')​ in the workflow I was discussing above. To be honest I was not testing if its working properly.​​

        Comment


        • rabii
          rabii commented
          Editing a comment
          I think targetEntity\attribute('amountConverted')​​ and workflow\targetEntity\attribute('amountConverted') and bpm\targetEntity\attribute(ATTRIBUTE) are all identical and they allow you to access targetEntity attributes.
          When using formula in a task that creates or updates another record, the current entity (for the script) is switched to the record you are creating. To access attributes of the target record you can utilize the function targetEntity\attribute(ATTRIBUTE).

          I have not used any of bpm or workflow syntax and always used targetEntity\attribute(ATTRIBUTE) which does always the job. remember you can add your own formula functions and use them in formula script.

        • Jakub Grufik
          Jakub Grufik commented
          Editing a comment
          aight, thanks a lot for the info, appreciate it
      Working...
      X