help with Logic Hooks

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • timarebel
    Member
    • Jul 2021
    • 33

    help with Logic Hooks

    hello

    I'm trying tofetch an entity to show in another entity is that possible with logic hook
    I have tried to use AfterSave but i m not sure if i did it right

    <?php
    namespace Espo\Custom\Hooks\Comission;
    use Application\Espo\Modules\Sales\Entities\InvoiceIte m;
    use Application\Espo\Modules\Sales\Entities\invoice;

    class product extends Espo\Core\ORM\Repositories\RDB
    {
    public function afterSave( Invoice $Invoice , array $InvoiceItem)
    {
    if ($invoice->isNew() && !$InvoiceItem->get('InvoiceItemId')) {
    $Comission->set('InvoiceItemId');
    }
    }
    }
    ?>
  • emillod
    Active Community Member
    • Apr 2017
    • 1405

    #2
    Hello. I think you're doing this wrong. Please give me more conext, i'll try to help you.

    Comment


    • timarebel
      timarebel commented
      Editing a comment
      i just posted the details i hope it's clear
  • timarebel
    Member
    • Jul 2021
    • 33

    #3
    hello and thank you for your answer ;


    i m trying to grab invoice items to show when i click on comission i show get it inside of the comission

    i tried to work around it with workflow but not getting anything back
    Attached Files

    Comment

    • emillod
      Active Community Member
      • Apr 2017
      • 1405

      #4
      Okay, in this case i think you should create new relation between comissions and invoiceItems. And you can assign invoiceItem with advanced pack to comission

      Comment

      • timarebel
        Member
        • Jul 2021
        • 33

        #5
        i made the relation i even tried to use workflow but it's not working , maybe it's bug ?

        Comment

        • item
          Active Community Member
          • Mar 2017
          • 1476

          #6
          Hello,
          you are wrong..

          hook is for entity ..
          you declare false first : https://docs.espocrm.com/development/hooks/#example
          your namespace is hook.. you extend repository...

          so you can only get "item" .. with relation like this :
          $opportunityCollection = $entityManager ->getRepository('Account') ->getRelation($account, 'opportunities') ->limit(0, 10) ->where($whereClause) ->find();

          see doc : https://docs.espocrm.com/development/

          regards
          If you could give the project a star on GitHub. EspoCrm believe our work truly deserves more recognition. Thanks.​

          Comment

          • timarebel
            Member
            • Jul 2021
            • 33

            #7
            hello


            Thank you for the reply , if i understood well I have to enject the EntityManager first than follow with the relation ,it's a little bit advance for me as i just learning php so bare with my understanding !

            Comment

            • emillod
              Active Community Member
              • Apr 2017
              • 1405

              #8
              Of course item is right, that your hook is incorrect, but i just propose to use advanced pack, it is easier.
              Flowchart should be assigned to InvoiceItem, then create rule which will trigger flowchart after creation, and just set update of entity, take comission from invoice which is parent for invoiceItem, and assign this comission to invoiceItem relation field.

              Comment

              • timarebel
                Member
                • Jul 2021
                • 33

                #9
                flowchart or workflow ?

                Comment

                • emillod
                  Active Community Member
                  • Apr 2017
                  • 1405

                  #10
                  I preffer flowcharts, because it's more clear for me

                  Comment

                  • timarebel
                    Member
                    • Jul 2021
                    • 33

                    #11
                    i never used it , i m good at workflow but this one was tricky ! Do you have any recommendation where i can start with it ?

                    Comment

                    • emillod
                      Active Community Member
                      • Apr 2017
                      • 1405

                      #12
                      I understand. No problem. We can do this with workflow. Here you have example: https://i.imgur.com/O6vnGT5.png
                      I didn't added additional relations, but i assume that you did
                      1. Remember about creating workflow for INVOICE ITEM
                      2. Choose trigger After record created
                      3. Condition - comission link in INVOICE can't be empty. In this case i don't have comission link in invoices, so i used quote Important: You have to choose in condition relation field IN INVOICES, not in invoice items
                      4. Choose action: Update target record. Thanks to that you'll update invoice item with comission. Just choose to update field comission link in invoice items with field from invoices
                      It should work

                      Comment

                      • timarebel
                        Member
                        • Jul 2021
                        • 33

                        #13
                        hello ;


                        I already tried this , tried many ways but nothing for some reason not even log recored showing up ...bare in mind that my invoice Item is an entity itself .

                        i just want to fetch this entity to Comission entity !!

                        Comment

                        • emillod
                          Active Community Member
                          • Apr 2017
                          • 1405

                          #14
                          If you want i can schedule a ms teams meeting, maybe you're doing something wrong.

                          Comment

                          Working...