Announcement

Collapse
No announcement yet.

Workflow question : attributeFetched

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

  • Workflow question : attributeFetched

    Testing this workflow scenario:

    Entity : Account

    Trigger : After save


    When the record changes, I want to create a new Case for this account, with the name in the case description

    How do I reference the attributeFetched('name') of the Account in order to do that?



    Click image for larger version  Name:	image.png Views:	0 Size:	9.6 KB ID:	102992


    I also tried to first create the case record, then relate.


    Code:
    $caseId = record\create('Case', 'name', entity\attributeFetched('name'));
    $accountId = entity\attributeFetched('id');
    record\relate('Account', $accountId, 'case', $caseId);​
    Any suggestion? The case record gets created, but as far as I can debug the $caseId does not have the ID of the generated Case record.

  • #2
    Why do you need attributeFetched ? anyway because you are creating a new record, the workflow allow you to use a special formula to access the target record attributes, you need to do it as below

    PHP Code:
    description string\concatenate(workflow\targetEntity\attributeFetched('name'), ' is not valid anymore'); 

    read this in documentation https://docs.espocrm.com/administrat...mula-functions
    Rabii
    Web Dev

    Comment


    • #3
      Thank you, that makes sense indeed, and that works fine.

      Still open : the question why fetching of the ID and relating it does not work.

      Code:
      $caseId = record\create('Case', 'name', "whatever");
      $accountId = workflow\targetEntity\attributeFetched('id');
      record\relate('Account', $accountId, 'Case', $caseId);​​

      Comment


      • #4
        accessing the id directly is restricted for security reasons AFAK.

        What are you trying to achieve here, i don't get it. is this code in the create related action ?
        Rabii
        Web Dev

        Comment


        • #5
          It was an alternative attempt to create the related case record.

          - Create a case, and fetch the ID of the newly generated case record (according documentation, but ID is empty)
          - fetch the ID of the record that triggered the workflow (account.id) (works, checked)
          - relate both records. (fails)

          I am just curious how you would do it that way.

          Comment


          • #6
            if you use a simple formula script task then you can use the code as below:

            PHP Code:
            record\create('Case''name''whatever''accountId'id); 
            Rabii
            Web Dev

            Comment


            • #7
              Yep that is actually even shorter. Thank you for the hint.

              It would be really nice to debug or even send a notitication with a variable to inspect its value, like

              Code:
              ext\notify($caseId)
              which would allow me to look at $caseId

              because

              Code:
              $caseId = record\create('Case', 'name', "whatever");
              still gives me a NULL for $caseId. Why creating this record fails is quite difficult to assess.



              Comment

              Working...
              X