Announcement

Collapse
No announcement yet.

changing called details from AD before it is planted

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

  • changing called details from AD before it is planted

    I'm using a vBscript to pull information from AD and insert into an Outlook Signature, which works fine.

    What I want to do is change some of the information before it's planted. I'm using this command to insert my Direct Dial

    if (strPhone) Then objSelection.TypeText "DD: " & strPhone & Chr(11) which displays for example

    01111 111111 and I need it to change it to +44 111 111111

    I've had a play around with the' if left', etc but can't get it to change anything

    Could anyone help?

  • #2
    Re: changing called details from AD before it is planted

    Can you clarify -- are you wanting to update AD with the new number or just change the way you are displaying it in the Sig?
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: changing called details from AD before it is planted

      Ossian,

      I want the number/format changed in the sig, not to change the AD field. Basically when I call from AD it will plant it in the sig based upon what is populated in the AD field.

      Since the signature is for International emails, the format of the telephone is fine for our own Country and the default sig.

      Here's the entire code.

      On Error Resume Next
      Set objSysInfo = CreateObject("ADSystemInfo")
      Set WshShell = CreateObject("WScript.Shell")
      strUser = objSysInfo.UserName
      Set objUser = GetObject("LDAP://" & strUser)
      'map Active Directory objUser to str names'
      strName = objUser.FullName
      strTitle = objUser.Title
      strPhone = objUser.TelephoneNumber
      strMobile = objUser.Mobile
      strEmail = objUser.mail
      'Use Word (required) to create the format'
      Set objWord = CreateObject("Word.Application")
      Set objDoc = objWord.Documents.Add()
      Set objSelection = objWord.Selection
      objSelection.Style = "No Spacing"
      Set objEmailOptions = objWord.EmailOptions
      Set objSignatureObject = objEmailOptions.EmailSignature
      Set objSignatureEntries = objSignatureObject.EmailSignatureEntries
      'If you get problems with line spacing, use vbNewline instead of Chr(11)'
      'Select what is displayed in the Signature based upon the str to ObjUser mappings above'
      objSelection.Font.Bold = True
      objSelection.Font.Name = "Arial"
      objSelection.Font.Size = 11
      if (strCred) Then objSelection.TypeText strName & ", " & strCred Else objSelection.TypeText strName & Chr(11)
      objSelection.Font.Bold = False
      objSelection.TypeText strTitle & Chr(11)
      objSelection.TypeText "DD: " & strPhone & Chr(11)
      if (strMobile) Then objSelection.TypeText "Mobile: " & strMobile & Chr(11)
      objSelection.TypeParagraph()
      objSelection.TypeParagraph()
      'add the entire range of what you want displayed and set the font'
      Set objSelection = objDoc.Range()
      objSelection.Font.Name = "Arial"
      'Add a siganture entry, name it and assign to new message'
      objSignatureEntries.Add "Full Signature", objSelection
      objSignatureObject.NewMessageSignature = "Full Signature"
      'Save the content and exit'
      objDoc.Saved = True
      objWord.Quit

      Mark

      Comment


      • #4
        Re: changing called details from AD before it is planted

        OK, so something like:
        Assume number is read into strNum and is in UK format (starts with 0)

        strNum = right(strNum,len(strNum)-1) 'strips off left most digit
        strNum = "+44 " & strNum

        If some numbers are already in international format:

        if not left(strNum,1) = "+" then
        <insert above code>
        end if

        Note this is general VB/VBA syntax, not checked explicitly for vbscript
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: changing called details from AD before it is planted

          Cheers,

          I'll give that ago and report back, if it doesn't work I'll revoke my positive feedback lol

          Comment


          • #6
            Re: changing called details from AD before it is planted

            Ok,

            Doesn't seem to work, we're using strPhone, so I replaced all the strNum with this

            Here's the code I ended up with but it displays nothing

            strPhone = right(strPhone,len(strPhone)-1) 'strips off left most digit
            strPhone = "+44 " & strPhone
            if not left(strPhone,1) = "+" then
            objSelection.TypeText "DD: " & strPhone & Chr(11)
            end if

            Mmmm..

            Comment


            • #7
              Re: changing called details from AD before it is planted

              Working now.

              Comment


              • #8
                Re: changing called details from AD before it is planted

                OK -- mine was two separate fragments so would not work as you gave it in #6
                Would you care to post the final script?
                Tom Jones
                MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                PhD, MSc, FIAP, MIITT
                IT Trainer / Consultant
                Ossian Ltd
                Scotland

                ** Remember to give credit where credit is due and leave reputation points where appropriate **

                Comment


                • #9
                  Re: changing called details from AD before it is planted

                  Ok, I spoke too soon sort of.

                  If the number is populated the format planted is spot on.

                  If there is no number populated it displays DD: +44

                  So I'm seeing if a True statement will work

                  Comment


                  • #10
                    Re: changing called details from AD before it is planted

                    Sorted

                    strPhone = right(strPhone,len(strPhone)-1) 'strips off left most digit
                    strPhone = "+44 " & strPhone
                    if (objUser.TelephoneNumber) Then objSelection.TypeText "DD: " & strPhone & Chr(11)

                    Comment


                    • #11
                      Re: changing called details from AD before it is planted

                      Good one
                      Tom Jones
                      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                      PhD, MSc, FIAP, MIITT
                      IT Trainer / Consultant
                      Ossian Ltd
                      Scotland

                      ** Remember to give credit where credit is due and leave reputation points where appropriate **

                      Comment


                      • #12
                        Re: changing called details from AD before it is planted

                        Originally posted by marcopolo View Post
                        Sorted

                        strPhone = right(strPhone,len(strPhone)-1) 'strips off left most digit
                        strPhone = "+44 " & strPhone
                        if (objUser.TelephoneNumber) Then objSelection.TypeText "DD: " & strPhone & Chr(11)
                        Additionally, because the TelephoneNumber attribute of the user object accepts most string patterns entered, the script should do an extra check if the first diget is actually a 0 before replacing it with the country code. And it should check whether or not a certain country code was already provided to the number in AD (if the number already starts with a plus sign or not).

                        Code:
                        Const Countrycode = "+44"
                        
                        Set objSysInfo = CreateObject("ADSystemInfo")
                        Set WshShell = CreateObject("WScript.Shell")
                        strUser = objSysInfo.UserName
                        Set objUser = GetObject("LDAP://" & strUser)
                        
                        'map Active Directory objUser to str names'
                        strPhone = Trim(objUser.TelephoneNumber)
                        '<...>
                        
                        
                        For i = 1 To Len(strPhone)
                        
                        ' find position of first digit in string
                           If IsNumeric(Mid(strPhone, i, 1)) = true then
                        
                           ' check for a leading plus-sign
                             If i > 1 then
                               If  mid(strPhone, i-1, 1) = "+" _
                                 then strPhone = mid(strPhone, i-1) : exit For
                             ElseIf Instr(strPhone, "+") = 1 then
                                 exit For
                             End If
                        
                           ' All the phone numbers in the United Kingdom have 11 digits, the first of which is 0
                             If Instr(strPhone, "0") = i then
                               ' first digit is a 0, 
                               ' replace first digit with the country code.
                               strPhone = Countrycode & " " & mid(strPhone, i+1)
                               exit For
                             Else
                               strPhone = Empty
                               exit For
                             End If
                        
                           ElseIf i = Len(strPhone) then
                             strPhone = Empty : exit For
                           End If
                        Next 
                        
                        wsh.echo strPhone

                        Or by using regular expression so you can also count the amount of digits in the string,
                        Code:
                        Const Countrycode = "+44"
                        
                        Set objSysInfo = CreateObject("ADSystemInfo")
                        Set WshShell = CreateObject("WScript.Shell")
                        strUser = objSysInfo.UserName
                        Set objUser = GetObject("LDAP://" & strUser)
                        
                        'map Active Directory objUser to str names'
                        strPhone = Trim(objUser.TelephoneNumber)
                        '<...>
                        
                        
                        Do : With New RegExp : .Pattern = "\d"
                           .Global = false : Set objMatch = .Execute(strPhone)
                        
                        ' find position of first digit in string
                           If objMatch.Count = 1 then
                             firstdigit = objMatch(0).Value
                             i = Instr(strPhone, firstdigit)
                        
                           ' check for a leading plus-sign
                             If i > 1 then
                               If  mid(strPhone, i-1, 1) = "+" _
                                 then strPhone = mid(strPhone, i-1) : exit Do
                             ElseIf Instr(strPhone, "+") = 1 then
                                 exit Do
                             End If
                        
                           ' All the phone numbers in the United Kingdom have 11 digits, the first of which is 0
                             If firstdigit = "0" then
                               ' replace first digit with the country code.
                               strPhone = Countrycode & " " & mid(strPhone, i+1)
                        
                           ' The replaced phone number should now consist of (at leased) 12 digits
                               .Global = True
                               If not .Execute(strPhone).Count >= 12 then strPhone = Empty
                        
                             Else
                               strPhone = Empty
                             End If
                        
                           Else
                             strPhone = Empty
                           End If
                           exit Do
                        End With : Loop
                        
                        wsh.echo strPhone

                        /Rems

                        This posting is provided "AS IS" with no warranties, and confers no rights.

                        __________________

                        ** Remember to give credit where credit's due **
                        and leave Reputation Points for meaningful posts

                        Comment


                        • #13
                          Re: changing called details from AD before it is planted

                          Off the wall with this but why not just changed the details in AD.

                          Comment

                          Working...
                          X