Novell Home

Reformatting Contact Fields

Novell Cool Solutions: Tip
By Bryan Green

Digg This - Slashdot This

Posted: 15 Dec 2005
 

Problem

We needed a way to strip out special characters and reformat certain data fields.

Solution

I created a policy on our Manual Task Driver on the Subscriber Event Transformation rule. It strips out special characters and reformats the telephone, mobile, and pager attributes to either US or UK formatting, depending on the stripped phone number length.

Example

Place the following rules in a new policy or in your favorite one. We used our Manual Task Driver but these rules can be easily modified to be used in just about any driver. Make sure you allow the numbers through on your filter as at least a notify.

<rule>
  <description>Strip Telephone Number of Special Characters</description>
  <conditions>
    <and>
      <if-class-name op="equal">User</if-class-name>
      <if-op-attr name="Telephone Number" op="available"/>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS">
      <arg-string>
        <token-replace-all regex="[^0-9]">
          <token-op-attr name="Telephone Number"/>
        </token-replace-all>
      </arg-string>
    </do-set-local-variable>
    <do-set-local-variable name="L_ORIGINAL_PHONE_NUMBER_FIRST_CHAR">
      <arg-string>
        <token-substring length="1">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
  </actions>
</rule>


<rule>
  <description>Check for [0-1] as first character of Telephone Number</description>
  <conditions>
    <or>
      <if-local-variable name="L_ORIGINAL_PHONE_NUMBER_FIRST_CHAR" op="equal">
0</if-local-variable>
      <if-local-variable name="L_ORIGINAL_PHONE_NUMBER_FIRST_CHAR" op="equal">
1</if-local-variable>
    </or>
  </conditions>
  <actions>
    <do-set-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS">
      <arg-string>
        <token-substring start="1">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
  </actions>
</rule>


<rule>
  <description>Reformat Telephone Number for US</description>
  <conditions>
    <and>
      <if-local-variable mode="regex" name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS" op="equal">
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]</if-local-variable>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_REFORMATTED_PHONE_NUMBER_US">
      <arg-string>
        <token-text xml:space="preserve">(</token-text>
        <token-substring length="3">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">)</token-text>
        <token-text xml:space="preserve"> </token-text>
        <token-substring length="3" start="3">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring length="4" start="6">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
    <do-set-src-attr-value name="Telephone Number">
      <arg-value type="string">
        <token-local-variable name="L_REFORMATTED_PHONE_NUMBER_US"/>
      </arg-value>
    </do-set-src-attr-value>
  </actions>
</rule>


<rule>
  <description>Reformat Telephone Number for UK</description>
  <conditions>
    <and>
      <if-local-variable mode="regex" name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS" op="equal">
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]</if-local-variable>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_REFORMATTED_PHONE_NUMBER_UK">
      <arg-string>
        <token-text xml:space="preserve">(</token-text>
        <token-substring length="2">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">)</token-text>
        <token-text xml:space="preserve"> </token-text>
        <token-substring length="3" start="2">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring length="3" start="5">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring start="8">
          <token-local-variable name="L_ORIGINAL_PHONE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
    <do-set-src-attr-value name="Telephone Number">
      <arg-value type="string">
        <token-local-variable name="L_REFORMATTED_PHONE_NUMBER_UK"/>
      </arg-value>
    </do-set-src-attr-value>
  </actions>
</rule>


<rule>
  <description>Strip Pager Number of Special Characters</description>
  <conditions>
    <and>
      <if-class-name op="equal">User</if-class-name>
      <if-op-attr name="pager" op="available"/>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS">
      <arg-string>
        <token-replace-all regex="[^0-9]">
          <token-op-attr name="pager"/>
        </token-replace-all>
      </arg-string>
    </do-set-local-variable>
    <do-set-local-variable name="L_ORIGINAL_PAGER_NUMBER_FIRST_CHAR">
      <arg-string>
        <token-substring length="1">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
  </actions>
</rule>


<rule>
  <description>Check for [0-1] as first character of Pager Number</description>
  <conditions>
    <or>
      <if-local-variable mode="nocase" name="L_ORIGINAL_PAGER_NUMBER_FIRST_CHAR" op="equal">
0</if-local-variable>
      <if-local-variable mode="nocase" name="L_ORIGINAL_PAGER_NUMBER_FIRST_CHAR" op="equal">
1</if-local-variable>
    </or>
  </conditions>
  <actions>
    <do-set-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS">
      <arg-string>
        <token-substring start="1">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
  </actions>
</rule>


<rule>
  <description>Reformat Pager Number for US</description>
  <conditions>
    <and>
      <if-local-variable mode="regex" name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS" op="equal">
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]</if-local-variable>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_REFORMATTED_PAGER_NUMBER_US">
      <arg-string>
        <token-text xml:space="preserve">(</token-text>
        <token-substring length="3">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">)</token-text>
        <token-text xml:space="preserve"> </token-text>
        <token-substring length="3" start="3">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring length="4" start="6">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
    <do-set-src-attr-value name="pager">
      <arg-value type="string">
        <token-local-variable name="L_REFORMATTED_PAGER_NUMBER_US"/>
      </arg-value>
    </do-set-src-attr-value>
  </actions>
</rule>


<rule>
  <description>Reformat Pager Number for UK</description>
  <conditions>
    <and>
      <if-local-variable mode="regex" name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS" op="equal">
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]</if-local-variable>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_REFORMATTED_PAGER_NUMBER_UK">
      <arg-string>
        <token-text xml:space="preserve">(</token-text>
        <token-substring length="2">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">)</token-text>
        <token-text xml:space="preserve"> </token-text>
        <token-substring length="3" start="2">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring length="3" start="5">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring start="8">
          <token-local-variable name="L_ORIGINAL_PAGER_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
    <do-set-src-attr-value name="pager">
      <arg-value type="string">
        <token-local-variable name="L_REFORMATTED_PAGER_NUMBER_UK"/>
      </arg-value>
    </do-set-src-attr-value>
  </actions>
</rule>


<rule>
  <description>Strip Mobile Number of Special Characters</description>
  <conditions>
    <and>
      <if-class-name op="equal">User</if-class-name>
      <if-op-attr name="mobile" op="available"/>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS">
      <arg-string>
        <token-replace-all regex="[^0-9]">
          <token-op-attr name="mobile"/>
        </token-replace-all>
      </arg-string>
    </do-set-local-variable>
    <do-set-local-variable name="L_ORIGINAL_MOBILE_NUMBER_FIRST_CHAR">
      <arg-string>
        <token-substring length="1">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
  </actions>
</rule>

<rule>
  <description>Check for [0-1] as first character of Mobile Number</description>
  <conditions>
    <or>
      <if-local-variable mode="nocase" name="L_ORIGINAL_MOBILE_NUMBER_FIRST_CHAR" op="equal">0<
/if-local-variable>
      <if-local-variable mode="nocase" name="L_ORIGINAL_MOBILE_NUMBER_FIRST_CHAR" op="equal">1<
/if-local-variable>
    </or>
  </conditions>
  <actions>
    <do-set-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS">
      <arg-string>
        <token-substring start="1">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
  </actions>
</rule>


<rule>
  <description>Reformat Mobile Number for US</description>
  <conditions>
    <and>
      <if-local-variable mode="regex" name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS" op="equal">
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]</if-local-variable>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_REFORMATTED_MOBILE_NUMBER_US">
      <arg-string>
        <token-text xml:space="preserve">(</token-text>
        <token-substring length="3">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">)</token-text>
        <token-text xml:space="preserve"> </token-text>
        <token-substring length="3" start="3">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring length="4" start="6">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
    <do-set-src-attr-value name="mobile">
      <arg-value type="string">
        <token-local-variable name="L_REFORMATTED_MOBILE_NUMBER_US"/>
      </arg-value>
    </do-set-src-attr-value>
  </actions>
</rule>


<rule>
  <description>Reformat Mobile Number for UK</description>
  <conditions>
    <and>
      <if-local-variable mode="regex" name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS" op="equal">
[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]</if-local-variable>
    </and>
  </conditions>
  <actions>
    <do-set-local-variable name="L_REFORMATTED_MOBILE_NUMBER_UK">
      <arg-string>
        <token-text xml:space="preserve">(</token-text>
        <token-substring length="2">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">)</token-text>
        <token-text xml:space="preserve"> </token-text>
        <token-substring length="3" start="2">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring length="3" start="5">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
        <token-text xml:space="preserve">-</token-text>
        <token-substring start="8">
          <token-local-variable name="L_ORIGINAL_MOBILE_NUMBER_WO_SPECIALS"/>
        </token-substring>
      </arg-string>
    </do-set-local-variable>
    <do-set-src-attr-value name="mobile">
      <arg-value type="string">
        <token-local-variable name="L_REFORMATTED_MOBILE_NUMBER_UK"/>
      </arg-value>
    </do-set-src-attr-value>
  </actions>
</rule>


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell