Announcement

Collapse
No announcement yet.

Delete all data from Accounts, Contacts, etc..

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

  • Delete all data from Accounts, Contacts, etc..

    Is there a way to delete all data from Accounts, Contacts, Opportunities, Calls, Meetings and Tasks but LEAVE the data in Leads?

    Also, is there a way to check if a record is a duplicate when attempting to save it. I have an Event entity and I want to make sure the user doesn't save an event to the same date/time. Perhaps give a warning with a Yes/No if possible or just display a warning and then save but at least the user knows and can decide what to do.

    Thanks..

  • #2
    1) What do you mean with "delete all data"?

    2) https://forum.espocrm.com/forum/deve...uplicated-task

    PHP Code:
    return [
        
    'OR' => [
            [
                
    'dateStart>=' => $entity->get('dateStart'),
                
    'dateStart<=' => $entity->get('dateEnd')
            ],
            [
                
    'dateEnd>=' => $entity->get('dateStart'),
                
    'dateEnd<=' => $entity->get('dateEnd')
            ],
            [
                
    'dateStart>=' => $entity->get('dateStart'),
                
    'dateEnd<=' => $entity->get('dateEnd')
            ],
        ],
    ];
            ); 
    something like this, didn't tested

    But this will check only for duplicates in one Entity ,the same is creating.
    If you need to check for all event types, you can do it in before save hook, throwing the Error, if matching

    Comment


    • #3
      Thanks Tanya, the code worked great but please note the last section needs a small change ('dateStart<=' => $entity->get('dateStart'), 'dateEnd>=' => $entity->get('dateEnd')):

      PHP Code:
      return [
          
      'OR' => [
              [
                  
      'dateStart>=' => $entity->get('dateStart'),
                  
      'dateStart<=' => $entity->get('dateEnd')
              ],
              [
                  
      'dateEnd>=' => $entity->get('dateStart'),
                  
      'dateEnd<=' => $entity->get('dateEnd')
              ],
              [
                  
      'dateStart<=' => $entity->get('dateStart'),
                  
      'dateEnd>=' => $entity->get('dateEnd')
              ],
          ],
      ]; 

      Now how do I make this check after Updates as well? Not only after creating new records.

      Thanks!

      Comment


      • #4
        You could try to create a before save hook. If matches event, throw Error

        https://www.espocrm.com/documentatio...lopment/hooks/
        https://github.com/espocrm/espocrm/issues/742
        https://www.espocrm.com/documentation/development/orm/#user-content-find

        Comment


        • #5
          Thanks for the advice Tanya.

          I modified "\application\Espo\Services\Record.php" and changed checkForDuplicatesInUpdate to true "checkForDuplicatesInUpdate = true". I don't know if that's "Upgrade Safe" or even recommended but it works.

          Comment


          • #6
            It is not upgrade safe and you can set this parameter in your custom service as well. In this way it will be upgrade safe.

            Comment


            • #7
              One more thing please, I'm trying to add more conditions to the duplicate function:

              PHP Code:
              ...
              [
                      
              'dateStart>=' => $entity->get('dateStart'),
                      
              'dateStart<=' => $entity->get('dateEnd'),
                      
              'venue=' => $entity->get('venue'),
                      
              'eventStatus<>' => "Lost",
                      
              'eventStatus<>' => "Cancelled"
              ],
              ... 

              But the 'eventStatus<>' => "Lost", 'eventStatus<>' => "Cancelled" aren't being evaluated properly. Is the syntax right? Everything else works..
              Last edited by ashballan; 06-11-2018, 02:21 PM.

              Comment


              • #8
                'eventStatus!=' => ["Lost","Cancelled"]

                Comment


                • #9
                  That solves the issue, thanks!

                  Comment


                  • #10
                    OK, now I'm getting a strange issue, try this to reproduce please:

                    - Make sure you have "checkForDuplicatesInUpdate = true" in "\application\Espo\Services\Record.php" or override this variable in the Account entity so the system checks for duplicates.
                    - Take any existing Account and duplicate it, the system will warn about a duplicate. Change the name slightly to avoid the duplication and create the new account.
                    - Now, use the pencil icon next to the name to edit the new account name only, change it to match the original account name, now click Update. The system will display the account record info in this format:
                    .."website":"www.lematicltd.com","emailAddress":nu ll,"phoneNumber":"","type":"","industry":"","sicCo de":null,"billingAddressStreet":"Verdun ","billingAddressCity":"Verdun","billingAddressSta te":null,"billingAddressCountry":"Lebanon","billin gAddressPostalCode":null,"shippingAddressStreet":n ull,"shippingAddressCity":null,"shippingAddressSta te":null,"shippingAddressCountry":null,"shippingAd dressPostalCode":null,"description":null,"createdA t":"2018-05-09 16:07:54","modifiedAt":"2018-06-13 12:57:49","tags":null,"billingAddressRegion":null, "yearEstablished":null,"employeeCount":null,"regis trationNumber":null,"accountContacts":null,"intere sts":null,"potential":"Potential","marketSegment": "IT","comments":null,...

                    But, editing the record using the main "Edit" button behaves correctly displaying the duplicate record in a side panel as usual. Using the pencil edit causes issues.. seems like a bug?

                    Comment


                    • #11
                      Yes, there is no duplicate error handler on inline edit mode.
                      We will try to fix it.

                      Comment


                      • #12
                        Thanks!

                        Comment

                        Working...
                        X