Announcement

Collapse
No announcement yet.

How can I automatically assign a user to a contact?

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

  • How can I automatically assign a user to a contact?

    I have a workflow that creates a User once a Contact is created. (Formula is below, and Target Entity is Contact)

    Code:
    $emailAddress = string\substring(entity\attribute(emailAddress), 0);
    $userName = string\match($emailAddress, '/([^@]+)/');
    $password = password\generate();
    $hash = password\hash($password);
    $userId = record\create(
       'User', 'userName', $userName, 'password', $hash 'emailAddress', $emailAddress );
    How can I assign this User that I just created to the Contact that triggered its creation?? I tried many things including
    Code:
    assignedUserId = $userId
    but nothing worked till now (the Assigned User is not being shown in 'Assigned User' field in the Contact record)

  • #2
    Hi JosNas,

    Code:
    $userName = string\match(emailAddress, '/([^@]+)/');
    $password = password\generate();
    $hash = password\hash($password);
    $userId = record\create(
    'User', 'userName', $userName, 'lastName', $userName, 'password', $hash, 'emailAddress', emailAddress);
    assignedUserId = $userId;
    assignedUserName = $userName;

    Comment


    • #3
      Vadym Hi Vadym, thanks for your reply but it still didn't work. If you go to Contacts > Click on the created Contact (open his details view) > `Assigned User` Field on the right panel is still 'None'
      Attached Files
      Last edited by JosNas; 12-01-2021, 12:12 PM.

      Comment


      • #4
        Bumping this

        Comment


        • #5
          Hi JosNas,

          Provide a screenshot of the Workflow.

          Comment


          • #6
            This is the workflow that creates the user. I need this because this is what will give every User <-> Contact access to their own record (User X can edit only Contact record X but can also view others)
            Attached Files

            Comment


            • #7
              JosNas,

              This Formula must be in the Action -> Execute Formula Script. Not in the Conditions.

              Code:
              $userName = string\match(emailAddress, '/([^@]+)/');
              $password = password\generate();
              $hash = password\hash($password);
              $userId = record\create(
              'User', 'userName', $userName, 'lastName', $userName, 'password', $hash, 'emailAddress', emailAddress);
              assignedUserId = $userId;
              assignedUserName = $userName;
              Last edited by Vadym; 12-02-2021, 02:32 PM.

              Comment


              • JosNas
                JosNas commented
                Editing a comment
                I feel stupid haha. Sorry didn't notice that thanks a lot Vadym! It worked

            • #8
              You're welcome!

              Comment

              Working...
              X