Announcement

Collapse
No announcement yet.

formula help - assign team automatically when user is assigned to a lead

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

  • formula help - assign team automatically when user is assigned to a lead

    Hi,

    When a lead is manually assigned a user, I'd like that lead to also be automatically assigned to that user's team.

    I wrote this script

    ifThen(entity\isAttributeChanged(assignedUser.name ), teamsIds=assignedUser.teamsIds)

    based on other solutions I saw in this forum but it doesn't work for me.
    What am I doing wrong?

    Thanks

  • #2
    Hi selo,

    Please use this formula script:
    Code:
    ifThen(
       entity\isAttributeChanged('assignedUserId') && assignedUserId != null,
       entity\addLinkMultipleId('teams', assignedUser.teamsIds);
       );

    Comment


    • #3
      Hey lazovic , thank you so much for your help.

      The code you wrote does it, except that I didn't realize when I ask for the ID, it literally prints the ID in numerical value and not the team name.
      So I tried modifying it as such based on your code:

      Code:
      ifThen(
         entity\isAttributeChanged('assignedUserName') && assignedUser.name != null,
         entity\addLinkMultipleId('teams', assignedUser.teamsNames)
         );​
      when that didn't work, I tried this, which also didn't work

      Code:
      ifThen(
      entity\isAttributeChanged('assignedUserName') && assignedUser.name != null,
      entity\setAttribute(teamsNames, assignedUser.teamsNames);
      );​
      So I'd really appreciate your help once again, to put the team name under the section team and not the ID number.
      Last edited by selo; 11-07-2023, 06:16 PM.

      Comment


      • lazovic
        lazovic commented
        Editing a comment
        For the teams names to appear, you just need to refresh the browser page.

    • #4
      Simple as that, it didn't even occur to me, thank you!

      For anyone stumbling upon this discussion, so there is no confusion, if you're looking for EspoCRM to automatically update the team an entity is assigned to when the assigned user is changed, then this is the working code lazovic provided:

      Code:
      ifThen(
      entity\isAttributeChanged('assignedUserId') && assignedUserId != null,
      entity\addLinkMultipleId('teams', assignedUser.teamsIds);
      );​

      Comment


      • #5
        Hey @selo

        if you want to see the names the teams without refreshing the page, then you can you entity->set instead. Below is how i would use it:

        PHP Code:
        if (entity\isAttributeChanged('assignedUserId') && assignedUserId) {
            
        entity\setAttribute('teamsIds'assignedUser.teamsIds);
            
        entity\setAttribute('teamsNames'assignedUser.teamsNames);
        }
        ​ 
        Rabii
        Web Dev | Freelancer

        Comment


        • #6
          Works great! Thank you

          Comment

          Working...
          X