Multiple ID/Prefix for each Team - Auto-increment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxxicyxxx
    Junior Member
    • Mar 2021
    • 2

    Multiple ID/Prefix for each Team - Auto-increment

    Hello,
    We would like to start using EspoCRM at our company, but I can't find a solution to one of the needs.
    The request is for each team to have its own ID for the new records.
    For example:
    Blue Team - Blue User creates a new record in the Leads menu, then the ID (redID) should be blue21001

    Red Team - Red User creates a new record in the Leads menu, then the ID (blueID) should be red21001

    For each new record, increment the ID corresponding to the team.
    I tried it in Entity Manager, the Workflows interface, but not much success.
    Is there such a solution in this system?
    Thank you in advance for your answers!
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #2
    Hello,
    Could you tell me where exactly the field that should store blue21001 / red21001 is located? What the type of this field?

    > For each new record, increment the ID corresponding to the team.

    Does this logic should works for all entities, or you need it just for the Lead entity?

    Also, I'm curious is that correct that a Blue User affects a redID and a Red User affects blueID?

    Comment

    • xxxicyxxx
      Junior Member
      • Mar 2021
      • 2

      #3
      Hi Maximus,
      Thank you for the answer!
      I'm sorry, I actually misspelled User-ID pair. So Blue User has blueID, Red User has redID.
      We would only use the field in the Leads entity.
      The field type is not really defined yet. I tried the Number (Auto-increment) type, but also string field.

      Comment

      • Maximus
        Senior Member
        • Nov 2018
        • 2731

        #4
        Hi,
        sorry for the delayed reply.
        So this is my view of this logic:
        1. Create a Varchar type field colled for example 'leadId' (to store values like blue21001/red21001);
        2. Create 2 additional Integer type fields to store the previous teams' id (e.g. previousRedId, previousBlueId);
        3. Create a formula for the Lead entity to affect the field.
        Example:
        Code:
        $isRedTeam = env\userAttribute(entity\hasLinkMultipleId('teams' , 'your-red-team-id'));
        $isBlueTeam = env\userAttribute(entity\hasLinkMultipleId('teams' , 'your-blue-team-id'));
        
        ifThen(
            entity\isNew() && $isRedTeam,
            $newRedId = previousRedId + 1;
            leadId = string\concatenate('red2100', $newRedId);
            previousRedId = $newRedId
        );
        
        ifThen(
            entity\isNew() && $isBlueTeam,
            $newBlueId = previousBlueId + 1;
            leadId = string\concatenate('blue2100', $newBlueId);
            previousBlueId = $newBlueId
        );
        I didn't test this formula example so don't know whether it works. But it shows the main logic concept.

        If you need to make a creation of ID number more dynamic (e.g. printing red21022 instead of red210022), you need to create a more complex formula.

        Comment

        Working...