Announcement

Collapse
No announcement yet.

Can we Create Pop Up Reminder from Workflow ?

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

  • #16
    Originally posted by yubrajkafle View Post
    Then what should be the relation between custom entity and users ?
    I tested all types of Relationships and the results are as follows:
    - Reminders using Workflows are created with the following Relationships (we are talking about Administration -> Entity Manager -> Your_Entity_Name -> Relationships):
    Code:
    Many-to-One, One-to-One Right, One-to-One Left, Children-to-Parent
    - Reminders using Workflows are created only when the Users field is filled in (as shown in the screenshot 1)​ with the following Relationships (we are talking about Administration -> Entity Manager -> Your_Entity_Name -> Relationships):
    Code:
    One-to-Many, Many-to-Many
    ​That is, if you want Workflows to be able to create Reminders in your custom entity - you need to remove in Administration -> Entity Manager -> Your_Entity_Name -> Relationships types of Relationships: One-to-Many, Many-to-Many (as shown in the screenshot 2), or filled Users field​ in.​
    Attached Files
    Last edited by victor; 04-12-2023, 02:33 PM.

    Comment


    • #17
      Hello rabii could you please help me with my request? I have code in formula for lead that is changing assignedUserId if some conditions are met. Everything is working fine but I would also love to show popup notification with some text like "Assigned user on lead "lead name" has been changed!"

      Is this possible? I am not sure how to create it with syntax: record\create('Lead', 'entityId', id, type, 'Popup') - I am not sure where to set the text of the notification.

      Could you please help me?
      Thanks a lot.

      Code in formula:
      Code:
      ifThen(
          entity\isAttributeChanged('assignedUserId') && assignedUser.jeObchodnik == true && assignedUser.pocetLeaduAktualniKvartal >= 100,
          assignedUserId = entity\attributeFetched('assignedUserId')
          );​

      Comment


      • rabii
        rabii commented
        Editing a comment
        i think you could bake something using this cool feature error Handlers however only issue is the way the leads assignment is done, is it done lead by lead or by mass update ?

      • Jakub Grufik
        Jakub Grufik commented
        Editing a comment
        the assignment is being done one by one manually we are using: Current version: 7.3.3 at the moment but I will upgrade to 7.4 soon.

        I am sorry man I have to go off for today but I will get back as soon as possible.

        Thanks a lot for the help.

      • rabii
        rabii commented
        Editing a comment
        No worries mate, i have baked something for you. looks it is possible to do it using error handlers. i will post the solution for you here but this will require custom code that will replace the formula function. meanwhile to post full working code can you explain what is assignedUser.jeObchodnik == true??

    • #18
      Hey Jakub Grufik

      I hope you had a good weekend mate, as promised please find below the code and steps to implement the functionality you wanted from our discussion above. This is possible using the error handlers framework which nice and easy to implement.

      1 - Step one create a php class called BeforeUpdateUserAssignment.php under custom\Espo\Custom\Classes\RecordHooks\Lead (create these folders if they don't exist under custom folder) copy the code below (code is reflecting what the formula does) - please make sure to remove the code from the formula to avoid conflict (or at least comment the code on formula until you test this and make sure it works as you wanted):

      PHP Code:
      <?php


      namespace Espo\Custom\Classes\RecordHooks\Lead;

      use 
      Espo\Core\Record\Hook\UpdateHook;
      use 
      Espo\Core\Exceptions\ConflictSilent;
      use 
      Espo\Core\Exceptions\Error;
      use 
      Espo\Core\Utils\Json;

      use 
      Espo\Core\Record\UpdateParams;

      use 
      Espo\ORM\Entity;

      use 
      Espo\Modules\Crm\Entities\Lead as LeadEntity;
      use 
      Espo\ORM\EntityManager;

      /**
       * @implements UpdateHook<LeadEntity>
       */
      class BeforeUpdateUserAssignment implements UpdateHook
      {

          public function 
      __construct(private EntityManager $entityManager){}


          public function 
      process(Entity $entityUpdateParams $params): void
          
      {
              
      /** @var LeadEntity $entity */

              
      if (!$entity->isAttributeChanged('assignedUserId')) {
                  return;
              }

              
      $this->processAssignment($entity);
          }

          private function 
      processAssignment(Entity $entity): void
          
      {
              
      $assignedUser $entity->get('assignedUser');

              
      // Get the number of leads' count for the assigned user - based on what you have in formula
              
      $numberofLeads $assignedUser->get('pocetLeaduAktualniKvartal');

              
      // Get the jeObchodnik boolean - based on what you have on formula
              
      $jeObchodnik $assignedUser->get('jeObchodnik');

              
      // Check the condition and if it is true create an error and send it to the frontend
              
      if ($numberofLeads >= 100 && $jeObchodnik === true) {

                  throw 
      Error::createWithBody(
                      
      'leadAssignment',
                      
      Json::encode([
                          
      'assignedUserName' => $entity->get('assignedUserName'),
                          
      'count' => $numberofLeads,
                      ])
                  );
              }

          }

      }
      2 - Step two create a Lead.json (if it doesn't exist) under custom\Espo\Custom\Resources\metadata\recordDefs and copy the code below:

      PHP Code:
      {
          
      "beforeUpdateHookClassNameList": [
              
      "__APPEND__",
              
      "Espo\\Custom\\Classes\\RecordHooks\\Lead\\BeforeUp  dateUserAssignment"
          
      ]
      }
      ​ 
      3 - Step three create a Lead.json (if it doesn't exist) under custom\Espo\Custom\Resources\metadata\clientDefs and copy the code below:

      PHP Code:
      {
          
      "saveErrorHandlers": {
              
      "leadAssignment""custom:handlers/lead/lead-assignment-handler"
          
      }
      }
      ​ 
      4 - Final step create a file lead-assignment-handler.js under client\custom\src\handlers\lead (create these folders if they don't exist) and copy the code below:

      PHP Code:
      define('custom:handlers/lead/lead-assignment-handler', [], function () {

          return class {
              
      constructor(view) {
                  
      /** @type {module:views/record/detail.Class} */
                  
      this.view view;
              }

              
      process(data) {
                  
      let assigneduser data.assignedUserName;
                  
      let count data.count;

                  
      // If you want you can display a warning instead which will be displayed for few second and disapear - see commented code
                  // Espo.Ui.warning(assigneduser + ' has more than ' + count + ' Leads please reassign lead to another user', true);
                  
      Espo.Ui.error(assigneduser ' has more than ' count ' Leads please reassign lead to another user'true);
              }
          }
      });
      ​​ 
      Please find attached a video showing how it works, in the video just added a simple query so that the admin user if has more then or equals 4 leads then notify the user making the assignment. please note that even when clicking cancel it seems that the admin user is still assigned but it is not just refresh the page and system will reassign the assignedUser to previous one if there is one. Hope this helps.

      Let me know if you face any issues.

      Rabii
      Web Dev

      Comment


    • #19
      hello rabii hello man, the weekend was fine thank you. How was your weekend?

      Wow, it seems like you did some serious work on my task. Thanks a lot for the help and for your time mate. I really appreciate it.

      Now I am gonna take a look at it and hopefully, my skill will be enough to implement it

      Will update the post once I have some progress.


      Again - THANKS A LOT!!!

      Comment


      • rabii
        rabii commented
        Editing a comment
        just follow the steps, create the folders if they don't exist and create the files and copy and paste the code and it should work, as you can see from the video attached to the post i have used a different approach just to demonstrate how it works.

        Enjoy it man, let me know if there is anything else i can help with.

      • rabii
        rabii commented
        Editing a comment
        did the code work ? remember to comment any logic in the formula similar this to avoid conflict.

    • #20
      rabii hey man, seems like the code is somehow working. I have one issue tho.

      I am getting error 500: leadAssignment instead of custom message that the user has more than 100 leads.. I think there is problem in the step 3 because the file was already existing so I was not sure where to put your code in the json

      This is how it looks like:
      Code:
      {
          "kanbanViewMode": true,
          "color": "#d6a2c9",
          "iconClass": "fas fa-address-card",
          "saveErrorHandlers": {
              "leadAssignment": "custom:handlers/lead/lead-assignment-handler"
          },
          "dynamicLogic": {
              "fields": {
                  "faktAdresa": {
                      "visible": {
                          "conditionGroup": [
                              {
                                  "type": "isFalse",
                                  "attribute": "adresaAkoFakturacna"
                              }
                          ]
                      }
                  },
                  "gpsAdrStupne": {
                      "visible": {
                          "conditionGroup": [
                              {
                                  "type": "isNotEmpty",
                                  "attribute": "gpsAdr"
                              }
                          ]
                      }
                  },
                  "name": {
                      "required": {
                          "conditionGroup": [
                              {
                                  "type": "isEmpty",
                                  "attribute": "accountName"
                              },
                              {
                                  "type": "isEmpty",
                                  "attribute": "emailAddress"
                              },
                              {
                                  "type": "isEmpty",
                                  "attribute": "phoneNumber"
                              }
                          ]
                      }
                  },
                  "firmaVytvorena": {
                      "visible": null
                  },
                  "phoneNumber": {
                      "required": {
                          "conditionGroup": [
                              {
                                  "type": "isEmpty",
                                  "attribute": "emailAddress"
                              }
                          ]
                      }
                  },
                  "emailAddress": {
                      "required": {
                          "conditionGroup": [
                              {
                                  "type": "isEmpty",
                                  "attribute": "phoneNumber"
                              }
                          ]
                      }
                  },
                  "convertedAt": {
                      "visible": {
                          "conditionGroup": [
                              {
                                  "type": "and",
                                  "value": [
                                      {
                                          "type": "equals",
                                          "attribute": "status",
                                          "value": "Converted"
                                      },
                                      {
                                          "type": "isNotEmpty",
                                          "attribute": "convertedAt"
                                      }
                                  ]
                              }
                          ]
                      }
                  },
                  "datumNeberieHovor": {
                      "visible": {
                          "conditionGroup": [
                              {
                                  "type": "equals",
                                  "attribute": "status",
                                  "value": "New"
                              },
                              {
                                  "type": "isTrue",
                                  "attribute": "neberieHovorPredPrir"
                              }
                          ]
                      }
                  },
                  "neberieHovorPredPrir": {
                      "visible": {
                          "conditionGroup": [
                              {
                                  "type": "equals",
                                  "attribute": "status",
                                  "value": "New"
                              }
                          ]
                      }
                  },
                  "gpsApp": {
                      "visible": {
                          "conditionGroup": [
                              {
                                  "type": "isNotEmpty",
                                  "attribute": "gpsAdr"
                              }
                          ]
                      }
                  },
                  "addressState": {
                      "required": {
                          "conditionGroup": [
                              {
                                  "type": "equals",
                                  "attribute": "status",
                                  "value": "Assigned"
                              }
                          ]
                      }
                  },
                  "faktAdresaState": {
                      "required": {
                          "conditionGroup": [
                              {
                                  "type": "notEquals",
                                  "attribute": "status",
                                  "value": "New"
                              }
                          ]
                      }
                  }
              }
          }
      }​
      I added the code to the top of the json..(probably incorrect)
      Attached Files

      Comment


      • #21
        which version of espocrm you are running ?
        Rabii
        Web Dev

        Comment


        • #22
          rabii I got it man, it was typo in the lead-assignment-handler.js

          There was just one more * in the comment so it was not commenting out the line.

          Original code:
          Code:
          return class {
                  constructor(view) {
                      /** @type {module:views/record/detail.Class} */
                      this.view = view;
                  }​
          Adjusted code:
          Code:
          return class {
                  constructor(view) {
                      /* @type {module:views/record/detail.Class} */
                      this.view = view;
                  }​

          Comment


          • rabii
            rabii commented
            Editing a comment
            that is weird i have same code and it is working not sure why that cause the issue.

          • Jakub Grufik
            Jakub Grufik commented
            Editing a comment
            yeah it is weird, same issue is in the BeforeUpdateUserAssignment.php where I did not correct it but everything is working properly so I am not gonna comment it out

        • #23
          rabii it is now working exactly as expected! THANK YOU VERY MUCH mate! You are god tier dev! Appreciate your help man, great work!

          Click image for larger version

Name:	error.png
Views:	370
Size:	6.9 KB
ID:	92495

          Comment


          • rabii
            rabii commented
            Editing a comment
            you are welcome mate, glad it is working now.

          • Jakub Grufik
            Jakub Grufik commented
            Editing a comment
            lol man I am so happy at the moment I feel like a dev even when you did all the work
        Working...
        X