On Wed, 18 Jun 2014 21:22:13 +0000, KCMongo wrote:

> We use the Delimited Text Driver to create new user accounts that come
> over from an Extract from our HR system. Currently if the user is John
> Smith we grab the first letter of the first name and the last name (ie..
> jsmith) and check if that CN exists, if it does exist then the next rule
> try's josmith followed by Johsmith up to 4 characters of the first name,
> we've hit the point where it is failing at that and due to other systems
> we're are working on switching our user naming convention to a numbered
> system. Ie.. JSmith1, JSMith2,,,,JSmith50. My problem is I'm having
> trouble figuring out how to do a loop that will come up with the CN,
> check if it's out there, and increment it and then repeat until it finds
> that the CN doesn't exist then breaks out.


The best answer is the unique name token, as already pointed out, but if
you need to roll your own version of the unique name token, it's not that
hard to do. Here's one I use for generating a unique email address (first
initial + last name + optional counter digits + @niu.edu) from first name
and last name:

<actions>
<do-if>
<arg-conditions>
<and>
<if-op-attr name="Given Name" op="available"/>
</and>
</arg-conditions>
<arg-actions>
<do-set-local-variable name="gn" scope="policy">
<arg-string>
<token-op-attr name="Given Name"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
<arg-actions>
<do-set-local-variable name="gn" scope="policy">
<arg-string>
<token-dest-attr name="Given Name"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-if>
<do-if>
<arg-conditions>
<and>
<if-op-attr name="Surname" op="available"/>
</and>
</arg-conditions>
<arg-actions>
<do-set-local-variable name="sn" scope="policy">
<arg-string>
<token-op-attr name="Surname"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
<arg-actions>
<do-set-local-variable name="sn" scope="policy">
<arg-string>
<token-dest-attr name="Surname"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-if>
<do-set-local-variable name="TargetEmailAliasL" scope="policy">
<arg-string>
<token-lower-case>
<token-substring length="1" start="0">
<token-local-variable name="gn"/>
</token-substring>
<token-replace-all regex="[^a-z]" replace-with="">
<token-local-variable name="sn"/>
</token-replace-all>
</token-lower-case>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="TargetEmailAliasR" scope="policy">
<arg-string>
<token-text xml:space="preserve">@niu.edu</token-text>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="TargetEmailAlias" scope="policy">
<arg-string>
<token-local-variable name="TargetEmailAliasL"/>
<token-local-variable name="TargetEmailAliasR"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="counter" scope="policy">
<arg-string>
<token-text xml:space="preserve">1</token-text>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="Found" scope="policy">
<arg-node-set>
<token-query>
<arg-match-attr name="mailLocalAddress">
<arg-value type="string">
<token-local-variable name="TargetEmailAlias"/>
</arg-value>
</arg-match-attr>
</token-query>
</arg-node-set>
</do-set-local-variable>
<do-set-local-variable name="FoundCN" scope="policy">
<arg-node-set>
<token-query>
<arg-match-attr name="CN">
<arg-value type="string">
<token-local-variable name="TargetEmailAliasL"/>
</arg-value>
</arg-match-attr>
</token-query>
</arg-node-set>
</do-set-local-variable>
<do-while>
<arg-conditions>
<or>
<if-xpath op="true">count($Found)!=0</if-xpath>
<if-xpath op="true">count($FoundCN)!=0</if-xpath>
</or>
</arg-conditions>
<arg-actions>
<do-set-local-variable name="TargetEmailAlias" scope="policy">
<arg-string>
<token-local-variable name="TargetEmailAliasL"/>
<token-local-variable name="counter"/>
<token-local-variable name="TargetEmailAliasR"/>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="Found" scope="policy">
<arg-node-set>
<token-query>
<arg-match-attr name="mailLocalAddress">
<arg-value type="string">
<token-local-variable name="TargetEmailAlias"/>
</arg-value>
</arg-match-attr>
</token-query>
</arg-node-set>
</do-set-local-variable>
<do-set-local-variable name="FoundCN" scope="policy">
<arg-node-set>
<token-query>
<arg-match-attr name="CN">
<arg-value type="string">
<token-local-variable name="TargetEmailAliasL"/>
<token-local-variable name="counter"/>
</arg-value>
</arg-match-attr>
</token-query>
</arg-node-set>
</do-set-local-variable>
<do-set-local-variable name="counter" scope="policy">
<arg-string>
<token-xpath expression="$counter+1"/>
</arg-string>
</do-set-local-variable>
</arg-actions>
</do-while>
<do-set-dest-attr-value name="mailLocalAddress">
<arg-value type="string">
<token-local-variable name="TargetEmailAlias"/>
</arg-value>
</do-set-dest-attr-value>
<do-add-dest-attr-value name="Object Class">
<arg-value>
<token-text xml:space="preserve">inetLocalMailRecipient</token-text>
</arg-value>
</do-add-dest-attr-value>
</actions>


--
--------------------------------------------------------------------------
David Gersic dgersic_@_niu.edu
Knowledge Partner http://forums.netiq.com

Please post questions in the forums. No support provided via email.
If you find this post helpful, please click on the star below.