List contacts with document attachment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TripitakaBC
    Junior Member
    • Dec 2021
    • 5

    List contacts with document attachment

    I'm new with EspoCRM although having evaluated several packages (and wasted far too much time with SuiteCRM!) I'm loving its simplicity. I don't have extensions yet until I determine that there is the possibility of a 'long term relationship'. :-)

    Yes, I have searched on this site and Google before asking here...

    I run a B2C training company and each client is a Contact, not an account. I have followed the instructions and set Espo up accordingly. Each client has a standard document attached to their record.

    I need to be able to filter Contacts to pull up any Contact that does not have at least one attached document. I've tried creating relationships between the Document entity and the Contacts entity but no matter what I try, it seems that it doesn't work. Any indicator would do; the paperclip icon, the attachment name or something else but I'd like to be able to a) see an indicator in the Contacts list and b) use the search to find Contact records that do not (or do) have at least one attachment.

    Thanks in advance.
  • rabii
    Active Community Member
    • Jun 2016
    • 1250

    #2
    Hi TripitakaBC

    I think first thing to do is to set up espocrm as B2C CRM. Go to Administration/ settings (check B2C Mode Checkbox), it will turn crm to be a B2C one and will make contact as main centre entity that represents client also it will deactivate account entity.

    Please note that you don't need to create a relationship between contact and document it is already created by default when crm is installed, you can just show documents panel on each contact record just go to (administration/ entity manager/ contact / layout and then choose bottom and drag and drop the panels - see attached screen shoot).

    Best way is to buy Advanced Pack extension from Espocrm team, it is very powerful it will give you ability to create such reports easily, also it has a workflow and BPMN that would allow you to automate so many processes in your business. https://www.espocrm.com/extensions/

    Good Luck
    Attached Files
    Rabii
    Web Dev

    Comment

    • TripitakaBC
      Junior Member
      • Dec 2021
      • 5

      #3
      Hi rabii and thanks for your response.

      As stated in my original post, I am already set up according to the instructions for B2C. That is not the question I have.

      To be specific, I am trying to figure out how to show an indication of whether a contact has, or does not have, an attachment without having to go into each individual contact record. The obvious route would be to have a, field from the 'Documents' entity available here

      (~/espocrm/#Admin/layouts/scope=Contact&type=list&em=true)

      but it doesn't show so I tried adding it. I can add a relationship from 'Documents' here but in the list view of contacts, the field always appears blank, even for contacts that do have attachments.

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1250

        #4
        Hi TripitakaBC

        I understand, as mentioned before you could still try few codes until you crack it but if i were you i would consider using workflow from Advanced Pack and you could create a flow that mark contact as (has documents) when a contact is linked to a document. it will be much easier; however i think there is a way, first of all you should know that contacts field is not available on document entity by default so you should add the field, follow the steps below:

        1 - Go to administration / entity manager / contact / fields (add a new Boolean field name it hasDocuments) / add it to the contact's list view /detail view etc
        2 - Go to custom/Espo/Custom/Resources/metadata/entityDefs and create a a new file called Document.json and paste in the code below:
        Code:
        {
        "fields": {
        "contacts": {
        "type": "linkMultiple",
        "layoutDetailDisabled": true,
        "layoutListDisabled": true,
        "layoutMassUpdateDisabled": true,
        "importDisabled": true,
        "noLoad": true
        }
        }
        }
        3 - GO to administration / entity manager / Document / Formula and paste in the code below
        Code:
        ifThen(entity\isNew() && contactsIds != null,
        
        $i = 0;
        
        while(
        $i < array\length(contactsIds),
        (
        $contactId = record\findOne('Contact', 'createdAt', 'desc', 'id', array\at(contactsIds, $i));
        
        $hasDocuments = record\attribute('Contact', array\at(contactsIds, $i), 'hasDocuments');
        
        ifThen($contactId != null && $hasDocuments == false,
        record\update('Contact', $contactId, 'hasDocuments', true, modifiedAt, datetime\now());
        );
        
        $i = $i + 1;
        )
        );
        
        )
        the code above will automatically update the contact's field (hasDocuments) to be true whenever a document is created for a contact that didn't have any documents before. please see attached screenshot.

        I hope this helps.

        Cheers
        Attached Files
        Last edited by rabii; 12-21-2021, 01:08 AM.
        Rabii
        Web Dev

        Comment

        • esforim
          Active Community Member
          • Jan 2020
          • 2204

          #5
          Hi,

          Personally I advise that you can activate that but I say to leave the Accounts function still available to use.

          There is no good way to link multiple contact together but Accounts; although our business is mostly related to Contact we use Account very often. Since account is good to create multiple "family" relationship, and also their Workplace/Employment history.

          However it depend on your usage I suppose, restricting and removing Account might be get better data quality for you.

          Comment

          Working...