how to create a workflow update from child entity to parent entity?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • edward7097
    Member
    • Sep 2015
    • 55

    how to create a workflow update from child entity to parent entity?

    Hi, I created a workflow that from Case record created, workflow will "create related entity" to Task.

    but if i want to create a workflow from Task record saved, workflow will update back to the case linked, unfortunately I can't get any to work.

    For better picture, i show a simple example:

    1. Case Created ===> Create Related Entity (Task) to duplicate field from Case (example Case.Name, Case.Account and etc).

    2. Linked Task Saved and set to Completed ====> Update Related Entity (Parent Case) to close the parent case if linked task is set to completed.

    The 2nd workflow is not success. Any idea?

  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hello
    You can not update parent entity with workflow.
    You can create an afterSave hook for task

    Or
    You can create a relationship in Entity Manager between task and case. Set formula for this caseId field (if parentType='Case' caseId=parentId). And after that I think you can update this related entity with workflow

    Comment

    • edward7097
      Member
      • Sep 2015
      • 55

      #3
      Originally posted by tanya
      Hello
      You can not update parent entity with workflow.
      You can create an afterSave hook for task

      Or
      You can create a relationship in Entity Manager between task and case. Set formula for this caseId field (if parentType='Case' caseId=parentId). And after that I think you can update this related entity with workflow
      I'm not good in php, can you guide me what should i do in formula? Thanks in advance.

      Comment

      • tanya
        Senior Member
        • Jun 2014
        • 4308

        #4
        Hello
        https://www.youtube.com/watch?v=WDSTMNFZPLE - Entity Manager
        https://github.com/espocrm/documenta...ion/formula.md - Formula

        Comment

        • edward7097
          Member
          • Sep 2015
          • 55

          #5
          Thanks for your kind help.

          This is my formula: ifThenElse(parentType='Case', casePrimaryId=parentId)

          I tested create a Case and the workflow is created a Task that linked to Case, I did check the record it filled the caseid to relationship case_primary_id. (worked)

          But, i created a workflow after record saved, it will update the related entity case, it will created duplicate Task each time i edit the Task. Any idea?

          Comment

          • tanya
            Senior Member
            • Jun 2014
            • 4308

            #6
            Originally posted by edward7097
            1. Case Created ===> Create Related Entity (Task) to duplicate field from Case (example Case.Name, Case.Account and etc).
            Check Workflow trigger type if it is after record created. send me screenshots of all workflows, please

            Comment

            • edward7097
              Member
              • Sep 2015
              • 55

              #7
              Originally posted by tanya

              Check Workflow trigger type if it is after record created. send me screenshots of all workflows, please
              Hi, Thanks for your kindly response.

              1. Close Task - No issue at all, when i completed the task, workflow will close related case as well.

              2. Create Task after Case record saved - No issue when i created a new Case and workflow create and link a Task

              3. Edit Task - When i edit the Task, it will duplicate a same Task after saved.

              Comment

              • tanya
                Senior Member
                • Jun 2014
                • 4308

                #8
                Few tips

                Edit task - add in Any section - if fields, you want to copy, were changed
                Close task - in All section - is status was changed
                in formula ifThenElse(casePrimaryId==null,ifThenElse(parentTy pe='Case', casePrimaryId=parentId))

                Comment

                • edward7097
                  Member
                  • Sep 2015
                  • 55

                  #9
                  Originally posted by tanya
                  Few tips

                  Edit task - add in Any section - if fields, you want to copy, were changed
                  Close task - in All section - is status was changed
                  in formula ifThenElse(casePrimaryId==null,ifThenElse(parentTy pe='Case', casePrimaryId=parentId))
                  Hi, Thanks for your help but unfortunately "Edit Task" still not work that follow your guide, it create another duplicate Task after i click saved

                  Comment

                  • tanya
                    Senior Member
                    • Jun 2014
                    • 4308

                    #10
                    Create task can only "Create Task after Case record created" (you wrote 'saved', if it was true - it could be the reason on problem). I am not sure, workflow "after record created" triggered twice. Other workflows don't have the rules for task creating

                    Comment

                    • edward7097
                      Member
                      • Sep 2015
                      • 55

                      #11
                      Originally posted by tanya
                      Create task can only "Create Task after Case record created" (you wrote 'saved', if it was true - it could be the reason on problem). I am not sure, workflow "after record created" triggered twice. Other workflows don't have the rules for task creating
                      sorry it was my typo mistake, actually it is record created but not saved.

                      the other task workflow doesn't create duplicate task for example completed task, workflow will trigger and close the case

                      Comment

                      • tanya
                        Senior Member
                        • Jun 2014
                        • 4308

                        #12
                        Check also workflow log (arrow next to Create Workflow button). Wherever case workflow after created triggered once or twice.

                        Comment

                        Working...