<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hi Martin,<br>
    <br>
    the sample referenced by Jason should work for having unique
    emailAddress attribute and not doing anything with user/name. I have
    not used this combination in my projects.<br>
    <br>
    For defining emailAddress as unique: maybe this blog could help:<br>
    <a class="moz-txt-link-freetext" href="https://evolveum.com/blog/unique-e-mail-address-value/">https://evolveum.com/blog/unique-e-mail-address-value/</a><br>
    <br>
    See the mapping "My object template: Validate emailAddress
    uniqueness". MidPoint will throw an exception whenever the new value
    of emailAddress attribute is already used in other midPoint user.
    It's quite ugly, but it works.<br>
    <br>
    Regards,<br>
    Ivan<br>
    <br>
    <div class="moz-cite-prefix">On 06/23/2016 04:59 PM, Martin Marchese
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAG3rmdoO9E5wNKfofvs52FHLEvWn0B61CKnXaPrNkxMmhXigUA@mail.gmail.com"
      type="cite">
      <div dir="ltr">To clarify, we are facing 2 different problems:
        <div><br>
        </div>
        <div>- Defining emailAddress as unique within the MidPoint
          schema (is this possible?), to get MidPoint return an error
          whenever the emailAddress already exists.</div>
        <div><br>
        </div>
        <div>- Generating an unique emailAddress from the
          objectTemplate, but not the username.</div>
        <div><br>
        </div>
        <div>Thanks in Advance</div>
      </div>
      <div class="gmail_extra"><br clear="all">
        <div>
          <div class="gmail_signature" data-smartmail="gmail_signature">
            <div dir="ltr">
              <div>
                <div dir="ltr"><b><span></span><span></span>Ing. Martín
                    Marchese</b><br>
                  <img moz-do-not-send="true"
                    src="http://www.identicum.com/img/favicon.ico">Identicum
                  S.A.<br>
                  Anchorena 1357 PB<br>
                  Tel: +54 (11) 3526.5509<br>
                  <a moz-do-not-send="true"
                    href="mailto:mmarchese@identicum.com"
                    target="_blank">mmarchese@identicum.com</a><br>
                  <a moz-do-not-send="true"
                    href="http://www.identicum.com" target="_blank">www.identicum.com</a></div>
              </div>
            </div>
          </div>
        </div>
        <br>
        <div class="gmail_quote">On Thu, Jun 23, 2016 at 11:00 AM,
          Martin Marchese <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:mmarchese@identicum.com" target="_blank">mmarchese@identicum.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div dir="ltr">Thanks Ivan,
              <div><br>
              </div>
              <div>In fact, I just need to get uniqueness in the
                emailAddress (I've already have username uniqueness
                since it's a personal ID #). The emailAddress, has
                nothing to do with the username in our design. Is there
                another way to achieve a field uniqueness?</div>
              <div><br>
              </div>
              <div>Regards,</div>
            </div>
            <div class="gmail_extra"><span class=""><br clear="all">
                <div>
                  <div data-smartmail="gmail_signature">
                    <div dir="ltr">
                      <div>
                        <div dir="ltr"><b><span></span><span></span>Ing.
                            Martín Marchese</b><br>
                          <img moz-do-not-send="true"
                            src="http://www.identicum.com/img/favicon.ico">Identicum
                          S.A.<br>
                          Anchorena 1357 PB<br>
                          Tel: +54 (11) 3526.5509<br>
                          <a moz-do-not-send="true"
                            href="mailto:mmarchese@identicum.com"
                            target="_blank">mmarchese@identicum.com</a><br>
                          <a moz-do-not-send="true"
                            href="http://www.identicum.com"
                            target="_blank">www.identicum.com</a></div>
                      </div>
                    </div>
                  </div>
                </div>
                <br>
              </span>
              <div>
                <div class="h5">
                  <div class="gmail_quote">On Thu, Jun 23, 2016 at 3:23
                    AM, Ivan Noris <span dir="ltr"><<a
                        moz-do-not-send="true"
                        href="mailto:ivan.noris@evolveum.com"
                        target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:ivan.noris@evolveum.com">ivan.noris@evolveum.com</a></a>></span>
                    wrote:<br>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div bgcolor="#FFFFFF" text="#000000"> Hi Martin,<br>
                        <br>
                        my guess is that you are using object template,
                        where name is not generated using
                        iterationToken. I have searched our samples for
                        the object template you've pasted and found one
                        - possibly the same.<br>
                        <br>
                        The iterationToken in emailAddress will be
                        non-empty only if the iterator was used to
                        generate the unique name.<br>
                        So, for example, if I tried to create one user
                        called identicum01 (given: John, family: Smith)
                        and another user called identicum02 (given:
                        John, family: Smith), the usernames are unique,
                        so the emailAddress attribute will both contain
                        empty iterationToken, which is indeed not
                        expected. The iterationToken is only used when
                        you have configured the mapping for user/name
                        attribute to use it. And then you can use
                        iterationToken also in other mappings.<br>
                        <br>
                        If user/name is generated from given and family
                        names, iterationToken would be used for both
                        user/name values, and the same value would then
                        be used in the emailAddress. The iterationToken
                        is single-value attribute stored in User object
                        and triggered only if the username is not unique
                        and the mapping for user/name is using the
                        iterationToken.<br>
                        <br>
                        See my attached object template; I've just tried
                        it with the following use case:<br>
                        1. create new user in midPoint, givenName: John,
                        familyName: Smith, password: whatever. No name
                        attribute filled. Save.<br>
                        Username JSmith was generated, <a
                          moz-do-not-send="true"
                          href="mailto:emailAddress=JSmith@domain.com"
                          target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:emailAddress=JSmith@domain.com">emailAddress=JSmith@domain.com</a></a><br>
                        2. create new user in midPoint, givenName: John,
                        familyName: Smith, password: whatever. No name
                        attribute filled. Save.<br>
                        Username JSmith1 was generated, <a
                          moz-do-not-send="true"
                          href="mailto:emailAddress=JSmith1@domain.com"
                          target="_blank"><a class="moz-txt-link-abbreviated" href="mailto:emailAddress=JSmith1@domain.com">emailAddress=JSmith1@domain.com</a></a><br>
                        <br>
                        I think this is what you were trying to achieve.<br>
                        Of course you need to specify the mapping
                        strength as normal or strong if you wish to
                        generate new user/name and user/emailAddress
                        whenever user is renamed. If you don't need
                        this, and only wish to set it for the very first
                        time, weak is OK.<br>
                        <br>
                        See also <a moz-do-not-send="true"
                          href="https://jira.evolveum.com/browse/MID-1977"
                          target="_blank">https://jira.evolveum.com/browse/MID-1977</a><br>
                        <br>
                        Regards,<br>
                        Ivan<br>
                        <br>
                        <objectTemplate xmlns=<a
                          moz-do-not-send="true"
                          href="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
                          target="_blank"><a class="moz-txt-link-rfc2396E" href="http://midpoint.evolveum.com/xml/ns/public/common/common-3">"http://midpoint.evolveum.com/xml/ns/public/common/common-3"</a></a><br>
                                       
                        xmlns:icfs=<a moz-do-not-send="true"
href="http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"
                          target="_blank">"http://midpoint.evolveum.com/xml/ns/public/connector/icf-1/resource-schema-3"</a><br>
                                        xmlns:t=<a
                          moz-do-not-send="true"
                          href="http://prism.evolveum.com/xml/ns/public/types-3"
                          target="_blank"><a class="moz-txt-link-rfc2396E" href="http://prism.evolveum.com/xml/ns/public/types-3">"http://prism.evolveum.com/xml/ns/public/types-3"</a></a><br>
                                        xmlns:c=<a
                          moz-do-not-send="true"
                          href="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
                          target="_blank"><a class="moz-txt-link-rfc2396E" href="http://midpoint.evolveum.com/xml/ns/public/common/common-3">"http://midpoint.evolveum.com/xml/ns/public/common/common-3"</a></a><br>
                                        xmlns:q=<a
                          moz-do-not-send="true"
                          href="http://prism.evolveum.com/xml/ns/public/query-3"
                          target="_blank"><a class="moz-txt-link-rfc2396E" href="http://prism.evolveum.com/xml/ns/public/query-3">"http://prism.evolveum.com/xml/ns/public/query-3"</a></a><br>
                                       
                        xmlns:ri=<a moz-do-not-send="true"
                          href="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"
                          target="_blank">"http://midpoint.evolveum.com/xml/ns/public/resource/instance-3"</a><br>
                                       
                        oid="c0c010c0-d34d-b33f-f00d-777222222333"<br>
                                        version="1"><span><br>
                             <name>User Template CSV
                          sync</name><br>
                        </span>    <description><br>
                                    Alternative User Template Object.<br>
                                    This object is used when creating a
                        new account, to set it up as needed.<br>
                                        </description><br>
                           <metadata><br>
                             
<createTimestamp>2016-06-23T08:14:13.745+02:00</createTimestamp><br>
                              <creatorRef
                        oid="00000000-0000-0000-0000-000000000002"
                        type="c:UserType"><!-- administrator
                        --></creatorRef><br>
                             
                        <createChannel><a moz-do-not-send="true"
href="http://midpoint.evolveum.com/xml/ns/public/model/channels-3#objectImport"
                          target="_blank">http://midpoint.evolveum.com/xml/ns/public/model/channels-3#objectImport</a></createChannel><br>
                           </metadata><span><br>
                             <iteration><br>
                               
                          <maxIterations>10</maxIterations><br>
                                <tokenExpression><br>
                                   <script><br>
                                      <code><br>
                                    if (iteration == 0) {<br>
                                      return "";<br>
                                    } else {<br>
                                      return ""+iteration;<br>
                                    }<br>
                                  </code><br>
                                   </script><br>
                                </tokenExpression><br>
                             </iteration><br>
                        </span>    <mapping><br>
                              <description><br>
                                        Property mapping.<br>
                                        Defines how properties of user
                        object are set up.<br>
                                        This specific definition sets a
                        full name as a concatenation<br>
                                        of givenName and familyName.<br>
                                                </description><br>
                              <strength>weak</strength><br>
                              <source><br>
                                
                        <c:path>$user/givenName</c:path><br>
                              </source><br>
                              <source><br>
                                
                        <c:path>$user/familyName</c:path><span><br>
                                </source><br>
                                <expression><br>
                                   <script><br>
                                     
                          <language><a moz-do-not-send="true"
href="http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy"
                            target="_blank">http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy</a></language><br>
                                      <code><br>
                        </span>
                                                                       
                        givenName + ' ' + familyName<br>
                                                               
                        </code><br>
                                 </script><br>
                              </expression><br>
                              <target><br>
                                 <c:path>fullName</c:path><br>
                              </target><br>
                           </mapping><span><br>
                             <mapping><br>
                                <strength>weak</strength><br>
                                <source><br>
                        </span>         
                        <c:path>givenName</c:path><br>
                              </source><br>
                              <source><br>
                                 <c:path>familyName</c:path><span><br>
                                </source><br>
                                <expression><br>
                                   <script><br>
                                     
                          <language><a moz-do-not-send="true"
href="http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy"
                            target="_blank">http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy</a></language><br>
                                      <code><br>
                                    def givenNameStr = ''+givenName<br>
                                    givenNameStr.substring(0,1) + '' +
                          familyName + iterationToken + '@<a
                            moz-do-not-send="true"
                            href="http://domain.com" target="_blank">domain.com</a>'<br>
                                  </code><br>
                                   </script><br>
                                </expression><br>
                                <target><br>
                        </span>         
                        <c:path>$user/emailAddress</c:path><br>
                              </target><br>
                           </mapping><span><br>
                             <mapping><br>
                                <strength>weak</strength><br>
                                <source><br>
                        </span>         
                        <c:path>givenName</c:path><br>
                              </source><br>
                              <source><br>
                                 <c:path>familyName</c:path><span><br>
                                </source><br>
                                <expression><br>
                                   <script><br>
                                     
                          <language><a moz-do-not-send="true"
href="http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy"
                            target="_blank">http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy</a></language><br>
                                      <code><br>
                                    def givenNameStr = ''+givenName<br>
                                    givenNameStr.substring(0,1) + '' +
                          familyName + iterationToken<br>
                        </span>         </code><br>
                                 </script><br>
                              </expression><br>
                              <target><br>
                                 <c:path>$user/name</c:path><br>
                              </target><br>
                           </mapping><br>
                        </objectTemplate>
                        <div>
                          <div><br>
                            <br>
                            <div>On 06/22/2016 07:03 PM, Martin Marchese
                              wrote:<br>
                            </div>
                          </div>
                        </div>
                        <blockquote type="cite">
                          <div>
                            <div>
                              <div dir="ltr">Hi all,
                                <div><br>
                                </div>
                                <div>I have an Object Template for
                                  users, and since I need email to be
                                  unique, I defined an iteration on it:</div>
                                <div><br>
                                </div>
                                <div>
                                  <div><i><font color="#999999"><objectTemplate

oid="c0c010c0-d34d-b33f-f00d-777222222333"></font></i></div>
                                  <div><i><font color="#999999"> 
                                        <name>User Template CSV
                                        sync</name></font></i></div>
                                  <div><i><font color="#999999"> 
                                        <iteration></font></i></div>
                                  <div><i><font color="#999999">   
                                        <maxIterations>10</maxIterations></font></i></div>
                                  <div><i><font color="#999999">   
                                        <tokenExpression></font></i></div>
                                  <div><i><font color="#999999">     
                                        <script></font></i></div>
                                  <div><i><font color="#999999">       
                                        <code></font></i></div>
                                  <div><i><font color="#999999">       
                                          if (iteration == 0) {</font></i></div>
                                  <div><i><font color="#999999">       
                                            return "";</font></i></div>
                                  <div><i><font color="#999999">       
                                          } else {</font></i></div>
                                  <div><i><font color="#999999">       
                                            return ""+iteration;</font></i></div>
                                  <div><i><font color="#999999">       
                                          }</font></i></div>
                                  <div><i><font color="#999999">       
                                        </code></font></i></div>
                                  <div><i><font color="#999999">     
                                        </script></font></i></div>
                                  <div><i><font color="#999999">   
                                        </tokenExpression></font></i></div>
                                  <div><i><font color="#999999"> 
                                        </iteration></font></i></div>
                                </div>
                                <div><i><font color="#999999">...</font></i></div>
                                <div><i><font color="#999999">...</font></i></div>
                                <div><i><font color="#999999"><br>
                                    </font></i></div>
                                <div><font color="#000000">And then
                                    within the emailAddress mapping:</font></div>
                                <div><font color="#000000"><br>
                                  </font></div>
                                <div><font>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"><mapping></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                       
                                      <strength>weak</strength></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        <source></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                         
                                      <path>givenName</path></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        </source></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        <source></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                         
                                      <path>familyName</path></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        </source></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        <expression></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                          <script></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                            <language><a
                                        moz-do-not-send="true"
href="http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy"
                                        target="_blank"><a class="moz-txt-link-freetext" href="http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy">http://midpoint.evolveum.com/xml/ns/public/expression/language#Groovy</a></a></language></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                            <code></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                              def givenNameStr =
                                      ''+givenName</div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                             
                                      givenNameStr.substring(0,1) + '' +
                                      familyName + iterationToken + '@<a
                                        moz-do-not-send="true"
                                        href="http://domain.com"
                                        target="_blank">domain.com</a>'</div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                            </code></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                          </script></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        </expression></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        <target></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                         
                                      <path>$user/emailAddress</path></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                        </target></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"> 
                                      </mapping></div>
                                    <div
                                      style="color:rgb(153,153,153);font-style:italic"><br>
                                    </div>
                                    <div><font color="#000000">The
                                        problem is that whenever I
                                        create a user, the email is
                                        always being set as if the
                                        iterationToken is '' and this
                                        result on duplicate emailAddress
                                        attribute among users.</font></div>
                                    <div><font color="#000000"><br>
                                      </font></div>
                                    <div><font color="#000000">Is there
                                        something I'm doing wrong?</font></div>
                                    <div><font color="#000000"><br>
                                      </font></div>
                                    <div><font color="#000000">Thanks in
                                        Advance</font></div>
                                  </font></div>
                                <div><br clear="all">
                                  <div>
                                    <div
                                      data-smartmail="gmail_signature">
                                      <div dir="ltr">
                                        <div>
                                          <div dir="ltr"><b><span></span><span></span>Ing.

                                              Martín Marchese</b><br>
                                            <img moz-do-not-send="true"
src="http://www.identicum.com/img/favicon.ico">Identicum S.A.<br>
                                            Anchorena 1357 PB<br>
                                            Tel: +54 (11) 3526.5509<br>
                                            <a moz-do-not-send="true"
                                              href="mailto:mmarchese@identicum.com"
                                              target="_blank">mmarchese@identicum.com</a><br>
                                            <a moz-do-not-send="true"
                                              href="http://www.identicum.com"
                                              target="_blank">www.identicum.com</a></div>
                                        </div>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                              </div>
                              <br>
                              <fieldset></fieldset>
                              <br>
                            </div>
                          </div>
                          <pre>_______________________________________________
midPoint mailing list
<a moz-do-not-send="true" href="mailto:midPoint@lists.evolveum.com" target="_blank">midPoint@lists.evolveum.com</a>
<a moz-do-not-send="true" href="http://lists.evolveum.com/mailman/listinfo/midpoint" target="_blank">http://lists.evolveum.com/mailman/listinfo/midpoint</a><span><font color="#888888">
</font></span></pre>
                          <span><font color="#888888"> </font></span></blockquote>
                        <span><font color="#888888"> <br>
                            <pre cols="72">-- 
  Ing. Ivan Noris
  Senior Identity Management Engineer & IDM Architect
  <a moz-do-not-send="true" href="http://evolveum.com" target="_blank">evolveum.com</a>                     <a moz-do-not-send="true" href="http://evolveum.com/blog/" target="_blank">evolveum.com/blog/</a>
  ___________________________________________________
  "Semper ID(e)M Vix."
</pre>
                          </font></span></div>
                      <br>
                      _______________________________________________<br>
                      midPoint mailing list<br>
                      <a moz-do-not-send="true"
                        href="mailto:midPoint@lists.evolveum.com"
                        target="_blank">midPoint@lists.evolveum.com</a><br>
                      <a moz-do-not-send="true"
                        href="http://lists.evolveum.com/mailman/listinfo/midpoint"
                        rel="noreferrer" target="_blank">http://lists.evolveum.com/mailman/listinfo/midpoint</a><br>
                      <br>
                    </blockquote>
                  </div>
                  <br>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
midPoint mailing list
<a class="moz-txt-link-abbreviated" href="mailto:midPoint@lists.evolveum.com">midPoint@lists.evolveum.com</a>
<a class="moz-txt-link-freetext" href="http://lists.evolveum.com/mailman/listinfo/midpoint">http://lists.evolveum.com/mailman/listinfo/midpoint</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
  Ing. Ivan Noris
  Senior Identity Management Engineer & IDM Architect
  evolveum.com                     evolveum.com/blog/
  ___________________________________________________
  "Semper ID(e)M Vix."
</pre>
  </body>
</html>