CRM news and views from Simon Jackson

Monday, March 26, 2007

Bind to the user object in Active Directory with the LDAP provider.

I had to get the email address of the current user logged onto a PC using Word VBA today.

I decided to look around for code to pull this from Active Directory.I found a good piece of code that will bind to the current logged on users object in Active Directory using the LDAP provider.

Thanks to Richard Mueller for posting the code on usenet: http://groups.google.co.uk/group/microsoft.public.adsi.general/browse_thread/thread/14ddf396e723a2e9/15dae72e5a730ee2?lnk=st&q=%22EmailAddress%22+property&rnum=1&hl=en#15dae72e5a730ee2

You can expand the below code to pull any property methods available for user objects. A spreadsheet can be found here:
http://www.rlmueller.net/References/PropertyMethods.xls


Public Function Email() As String

'Example using NameTranslate to convert NT logon name to Distinguished Name:

Dim objNetwork As Variant
Dim objRootDSE As Variant
Dim objTrans As Variant
Dim objUser As Variant
Dim strDNSDomain As String
Dim strNTName As String
Dim strNetBIOSDomain As String
Dim strUserDN As String


Set objNetwork = CreateObject("Wscript.Network")
strNTName = objNetwork.UserName


' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")


' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init 3, strDNSDomain
objTrans.Set 1, strDNSDomain
strNetBIOSDomain = objTrans.Get(3)
' Remove trailing backslash
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)


' Use the NameTranslate object to convert the NT user name to the
' Distinguished Name required for the LDAP provider.
objTrans.Init 1, strNetBIOSDomain
objTrans.Set 3, strNetBIOSDomain & "\" & strNTName
strUserDN = objTrans.Get(1)


' Bind to the user object in Active Directory with the LDAP provider.
Set objUser = GetObject("LDAP://" & strUserDN)

Email = objUser.Get("mail")


End Function

Labels: , ,

Saturday, March 03, 2007

Vista and stability

Why do I do it, Microsoft release a new operating system and I have to install it, it madness.
How easily I've forgotten the issues I had adopting Windows XP early. So now I have to pay the price, suffering with bugs, glitches and unsupported drivers, I do wonder if it's worth it. I've had 3 bsod's with vista business, today it just went utterly mental, deciding to display every single process(I assume) as a window, one minute I'm happy as Larry, then next BANG, the screen flickers, and a 100 odd windows open all over the place, just look at the task bar. If things don't settle down I'll be going back to Windows XP. Lets prey I've learnt a lesson for next time MS release a new OS.

Friday, March 02, 2007

CRM Javascript

Michael Höhne a CRM MVP has collated a list of handy JavaScript snippets that are frequently requested in the Microsoft CRM newsgroups.

The folloing snippets are listed (as of 2-Mar-2007)
  • Replacing the content of an IFRAME
  • Adding additional values to duration fields
  • Changing the title of a CRM form
  • Changing the Link of a Ticker Symbol from MSN Money to Yahoo Finances
  • Counting the number of backslashes in a string
  • Changing the label of a field at runtime
  • Changing the color of a single option in a picklist
  • Opening a new window without the IE menu and status bars
  • Disabling a form at runtime
  • Automatically changing the value of a text field to capitals
  • Getting notified when the user selects a another tab on a form
  • The current record id
  • The current object type code
  • Initializing a date field with the current date
  • Changing the URL of an IFRAME at runtime
  • Displaying a picture in a CRM form, using a text field to store the data source
  • Changing the default lookup type
  • Calculating a date field based upon the selection of a picklist
  • Creating a new email when double-clicking a standard text field
  • Resetting a field value if validation fails
  • Inserting line breaks in a text area control
  • Hiding an entire row of a CRM form
http://www.stunnware.com/crm2/data/More%20JavaScript%20code.htm

Labels: ,